错误:`output.path`需要是绝对path或`/`

我是React的初学者,目前我正在尝试基本的设置。 到目前为止,我已经安装了npm的基本模块,我的项目的文件夹结构如下所示。

文件夹结构

package.json显示了我已经安装的项目以及一个小的项目描述。

{ "name": "test", "version": "1.0.0", "description": "test", "main": "index.js", "scripts": { "start": "webpack-dev-server --hot" }, "repository": { "type": "git", "url": "https://github.com/theo82" }, "keywords": [ "test" ], "author": "Theo Tziomakas", "license": "ISC", "dependencies": { "react": "^15.4.2", "react-dom": "^15.4.2", "webpack": "^2.2.1", "webpack-dev-server": "^2.4.1" } } 

无论如何,当我打字npm开始 ,我得到这个错误。

 Error: `output.path` needs to be an absolute path or `/`. at Object.setFs (C:\Users\Theodosios\Desktop\reactApp\node_modules\webpack-d ev-middleware\lib\Shared.js:88:11) 

我相信这与webpack.config.js文件有关。

  var config = { entry: './main.js', output: { path:'./', filename: 'index.js', }, devServer: { inline: true, port: 3000 }, module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel', query: { presets: ['es2015', 'react'] } } ] } } module.exports = config; 

这个错误怎么解决?

谢谢,

泰奥?

您需要定义相对于webpack config的输出path。

 path: path.resolve(__dirname, './'), publicPath: '/', filename: 'bundle.js'