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

时间:2017-03-12 08:00:23

标签: javascript node.js reactjs

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

folder structure

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 start 时,我收到此错误。

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;

如何修复此错误?

谢谢,

西奥?

1 个答案:

答案 0 :(得分:1)

您需要定义相对于webpack配置的输出路径。

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