我的 webpack.config.js 是这样的:
js
var webpack = require('webpack'); module.exports = { entry: { zyfaq: "./app/zyfaq/zyfaq.js" }, output: { path: __dirname + '/public/js', filename: "[name].min.js" }, module: { loaders: [ { test: /\.css$/, loader: "style!css" } ] } };
错误提示:
module.js:338
throw err;
^
Error: Cannot find module 'webpack'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/cos800/zhaoyang/webpack.config.js:2:15)
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)
但是我把第一行 var webpack = require('webpack');
去掉就不会出错了。
我又重新安装 webpack 并安装到项目内,又出现以下错误:
% sudo cnpm install webpack
Password:
-
> fsevents@0.3.5 install /Users/cos800/zhaoyang/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/fsevents
> node-gyp rebuild
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: getaddrinfo ENOTFOUND npm.taobao.org
gyp ERR! stack at errnoException (dns.js:44:10)
gyp ERR! stack at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)
gyp ERR! System Darwin 14.1.0
gyp ERR! command "node" "/usr/local/lib/node_modules/cnpm/node_modules/npm-for-cnpm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/cos800/zhaoyang/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/fsevents
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
npm WARN optional dep failed, continuing fsevents@0.3.5
webpack@1.7.2 node_modules/webpack
├── supports-color@1.3.0
├── clone@0.1.19
├── tapable@0.1.8
├── memory-fs@0.2.0
├── async@0.9.0
├── mkdirp@0.5.0 (minimist@0.0.8)
├── optimist@0.6.1 (wordwrap@0.0.2, minimist@0.0.10)
├── enhanced-resolve@0.8.4 (graceful-fs@3.0.5)
├── esprima@1.2.5
├── uglify-js@2.4.16 (uglify-to-browserify@1.0.2, async@0.2.10, optimist@0.3.7, source-map@0.1.34)
├── node-libs-browser@0.4.3 (https-browserify@0.0.0, tty-browserify@0.0.0, constants-browserify@0.0.1, process@0.10.1, path-browserify@0.0.0, os-browserify@0.1.2, string_decoder@0.10.31, punycode@1.3.2, domain-browser@1.1.4, querystring-es3@0.2.1, assert@1.3.0, timers-browserify@1.4.0, stream-browserify@1.0.0, events@1.0.2, vm-browserify@0.0.4, console-browserify@1.1.0, util@0.10.3, http-browserify@1.7.0, readable-stream@1.1.13, url@0.10.3, buffer@3.0.3, browserify-zlib@0.1.4, crypto-browserify@3.2.8)
├── webpack-core@0.5.0 (source-map@0.4.1)
└── watchpack@0.2.3 (graceful-fs@3.0.5, chokidar@1.0.0-rc4)
看看你的
project.json
里有没有"webpack": "^1.6.0"
。如果没有就安装。
加到你的依赖里。
在你代码看来,你不需要引入的。一般是用到webpack的插件的时候才引用他。