2017-03-12 88 views
1

我是React的初学者,目前我正在尝试基本设置。到目前为止,我从npm安装了基本模块,我的项目的文件夹结构如下所示。错误:`output.path`必须是绝对路径或`/`

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开始,我得到这个错误。

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; 

该错误如何解决?

谢谢,

Theo?

+3

'路径:__dirname' – Li357

+1

看看[这](http://stackoverflow.com/a/42166772/4248342)的答案。 –

+0

感谢安德鲁它的工作。 – Theo

回答

1

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

path: path.resolve(__dirname, './'), 
publicPath: '/', 
filename: 'bundle.js' 
相关问题