2017-02-06 148 views
0

我正在學習react.js。我已經運行了所有需要設置反應的命令js ,但是當我運行npm start時這個命令給我錯誤。我沒有理解這個問題。 當我運行npm start誤差如何解決這個錯誤js

Error: output.path needs to be an absolute path or / . at Object.setFs (C:\Users\Administrator\Desktop\reactApp\node_modules\webpac k-dev-middleware\lib\Shared.js:88:11) at Shared (C:\Users\Administrator\Desktop\reactApp\node_modules\webpack-dev- middleware\lib\Shared.js:214:8) at module.exports (C:\Users\Administrator\Desktop\reactApp\node_modules\webp ack-dev-middleware\middleware.js:22:15) at new Server (C:\Users\Administrator\Desktop\reactApp\node_modules\webpack- dev-server\lib\Server.js:56:20) at startDevServer (C:\Users\Administrator\Desktop\reactApp\node_modules\webp ack-dev-server\bin\webpack-dev-server.js:379:12) at processOptions (C:\Users\Administrator\Desktop\reactApp\node_modules\webp ack-dev-server\bin\webpack-dev-server.js:317:3) at Object. (C:\Users\Administrator\Desktop\reactApp\node_modules\ webpack-dev-server\bin\webpack-dev-server.js:441:1) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32)

npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\ node_modules\npm\bin\npm-cli.js" "start" npm ERR! node v7.3.0 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE npm ERR! [email protected] start: webpack-dev-server npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] start script 'webpack-dev-server'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the package.json package,

npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! webpack-dev-server npm ERR! You can get information on how to open an issue for this project with: npm ERR!
npm bugs package.json npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls package.json npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! C:\Users\Administrator\Desktop\reactApp\npm-debug.log

+0

,你的WebPack配置是錯誤的。 'output.path'必須是絕對路徑或'/'。請閱讀文檔以獲取如何解決此問題的示例:https://webpack.js.org/configuration/ –

回答

1

我遇到這個問題,昨天和今天我終於解決了它,我希望它可以幫助你。 在webpack.config.js,你應該使路徑絕對路徑,做到這一點,如下所示:

output:{ 
    path:__dirname + '/dist', 
    filename:"build.js" 
    }, 

__dirname是項目的路徑,DIST是要保存您的構建路徑。 JS,
並在您的index.html

<script src="/build.js"> 

    </script> 

的原因是由於錯誤稱的WebPack已經更新到webpack2

+0

將webpack.config.js中的'./any-dir'替換爲__dirname +'/ any-dir'我 。 – ImranNaqvi