0
votes

I am learning react.js. I have run all commands which needed for setup react js but when I run npm start this command give me the error. I have not understood the problem. When I run npm start the error is

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

1
As the error says, your Webpack config is wrong. output.path needs to be an absolute path or /. Read the docs for an example of how to solve this: webpack.js.org/configurationJoe Clay

1 Answers

1
votes

I meet this problem yesterday,and I finally solved it today,and I wish it can help you. in your webpack.config.js, you should make the path an absolute path,do it as the following:

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

__dirname is the path of your project,dist is the path you want to save your build.js,
and in your index.html

 <script src="/build.js">

    </script>

the reason is that the webpack has updated to webpack2