ningrixin
ningrixin

Reputation: 33

error with webpack when follow official tutorial

When I learn webpack I follow this tutorial: http://webpack.github.io/docs/tutorials/getting-started/ I run webpack ./entry.js bundle.js after I installed webpack(use the same command as the tutorial) and create just the exact files as the tutorail. Then I got the error.

 "module.js:338
    throw err;
    ^
Error: Cannot find module 'assert/'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.require.resolve (module.js:388:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-libs-browser/index.js:1:93)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/webpack/lib/node/NodeSourcePlugin.js:7:23)
"

The enviroment is osx 10.10.3 and node is v0.12.4. How can I fix this?

Upvotes: 3

Views: 3239

Answers (1)

Are you sure Webpack is installed correctly in your system?

Regardless of that it's preferable to use a local install. Here are some quick instructions so you can give it a go. Follow at your project directory:

  1. npm init
  2. Just hit return for everything unless you feel like tweaking some. This will generate package.json at your project root
  3. Hit npm i webpack --save-dev. This will attach Webpack as a development dependency to your project.
  4. Hit node_modules/.bin/webpack ./entry.js bundle.js

Alternatively you can set up a scripts section like this at your package.json:

{
    "scripts": {
        "build": "webpack ./entry.js bundle.js"
    }
}

If you hit npm run build after this, it will perform the same thing.

I go into a lot more detail at my freely available book about Webpack. You can find more advanced ways to deal with it there.

Upvotes: 1

Related Questions