2017-03-12 115 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' 
相關問題