webpack - Module not found: Error: Cannot resolve module 'server' -
i try use webpack managing files in project. use webpack-dev-server , bower-webpack-plugin. when run server, error in browser console.
module not found: error: cannot resolve module 'server'
webpack.config.js
const bowerwebpackplugin = require("bower-webpack-plugin"); module.exports = { entry: './src/script/index.jsx', output: { filename: 'bundle.js', //this default name, can skip //at directory our bundle file available //make sure port 8090 used when launching webpack-dev-server publicpath: 'http://localhost:8090/assets' }, devtool: 'source-map', module: { loaders: [ { test: /\.js[x]?$/, loaders: ['react-hot', 'jsx', 'babel'], exclude: /node_modules/ }, { test: /\.scss$/, loaders: [ 'style', 'css?sourcemap', 'sass?sourcemap' ] } ] }, plugins: [ new bowerwebpackplugin() ], externals: { //don't bundle 'react' npm package our bundle.js //but global 'react' variable 'react': 'react' }, resolve: { extensions: ['', '.js', '.jsx'], modulesdirectories: ["./src", "node_modules", "bower_components"] } }
edit: use this webpack config without bower-webpack-plugin
package.json
{ "scripts": { "start": "npm run serve | npm run dev", "serve": "./node_modules/.bin/http-server -p 8080", "dev": "webpack-dev-server --progress --colors --port 8090" }, "name": "wonder", "version": "0.0.0", "description": "internal app", "main": "./src/script/index.jsx", "author": "and", "license": "isc", "devdependencies": { "babel-core": "^5.8.22", "babel-loader": "^5.3.2", "bower-webpack-plugin": "^0.1.8", "css-loader": "^0.16.0", "extract-text-webpack-plugin": "^0.8.2", "http-server": "^0.8.0", "jsx-loader": "^0.13.2", "node-sass": "^3.2.0", "path": "^0.11.14", "react": "^0.13.3", "react-hot-loader": "^2.0.0-alpha-2", "reinstall": "^1.1.0", "sass-loader": "^2.0.1", "style-loader": "^0.12.3", "webpack": "^1.11.0", "webpack-dev-server": "^1.10.1" } }
browser console output
uncaught error: cannot find module "server" webpackmissingmodule @ bootstrap 19214e8f07aa8a69f314:39 (anonymous function) @ bootstrap 19214e8f07aa8a69f314:39 __webpack_require__ @ bootstrap 19214e8f07aa8a69f314:19 (anonymous function) @ bootstrap 19214e8f07aa8a69f314:39 (anonymous function) @ bootstrap 19214e8f07aa8a69f314:39 webpack-dev-server.js:1 [wds] errors while compiling. webpack-dev-server.js:1 multi main module not found: error: cannot resolve module 'server' in /users/and/devel/webpack_test resolve module server in /users/and/devel/webpack_test looking modules in /users/and/devel/webpack_test/src /users/and/devel/webpack_test/src/server doesn't exist (module directory) resolve 'file' server in /users/and/devel/webpack_test/src resolve file /users/and/devel/webpack_test/src/server.js doesn't exist /users/and/devel/webpack_test/src/server doesn't exist /users/and/devel/webpack_test/src/server.jsx doesn't exist looking modules in /users/and/devel/webpack_test/node_modules /users/and/devel/webpack_test/node_modules/server doesn't exist (module directory) resolve 'file' server in /users/and/devel/webpack_test/node_modules resolve file /users/and/devel/webpack_test/node_modules/server doesn't exist /users/and/devel/webpack_test/node_modules/server.js doesn't exist /users/and/devel/webpack_test/node_modules/server.jsx doesn't exist looking modules in /users/and/devel/webpack_test/bower_components /users/and/devel/webpack_test/bower_components/server doesn't exist (module directory) resolve 'file' server in /users/and/devel/webpack_test/bower_components resolve file /users/and/devel/webpack_test/bower_components/server doesn't exist /users/and/devel/webpack_test/bower_components/server.js doesn't exist /users/and/devel/webpack_test/bower_components/server.jsx doesn't exist resolve 'bower component' server manifest files using [bower.json] resolve file /users/and/devel/webpack_test/bower_components/server/bower.json doesn't exists /users/and/devel/webpack_test/src/server/bower.json doesn't exists /users/and/devel/webpack_test/node_modules/server/bower.json doesn't exists /users/and/devel/bower_components/server/bower.json doesn't exists /users/and/devel/src/server/bower.json doesn't exists /users/and/devel/node_modules/server/bower.json doesn't exists /users/and/bower_components/server/bower.json doesn't exists /users/and/src/server/bower.json doesn't exists /users/and/node_modules/server/bower.json doesn't exists /users/bower_components/server/bower.json doesn't exists /users/src/server/bower.json doesn't exists /users/node_modules/server/bower.json doesn't exists /bower_components/server/bower.json doesn't exists /src/server/bower.json doesn't exists /node_modules/server/bower.json doesn't exists [/users/and/devel/webpack_test/src/server.js] [/users/and/devel/webpack_test/src/server] [/users/and/devel/webpack_test/src/server] [/users/and/devel/webpack_test/src/server.jsx] [/users/and/devel/webpack_test/node_modules/server] [/users/and/devel/webpack_test/node_modules/server] [/users/and/devel/webpack_test/node_modules/server.js] [/users/and/devel/webpack_test/node_modules/server.jsx] [/users/and/devel/webpack_test/bower_components/server] [/users/and/devel/webpack_test/bower_components/server] [/users/and/devel/webpack_test/bower_components/server.js] [/users/and/devel/webpack_test/bower_components/server.jsx] @ multi main (anonymous function) @ webpack-dev-server.js:1 n.emit @ webpack-dev-server.js:1 r.onevent @ webpack-dev-server.js:1 r.onpacket @ webpack-dev-server.js:1 t.exports @ webpack-dev-server.js:1 n.emit @ webpack-dev-server.js:1 r.ondecoded @ webpack-dev-server.js:1 t.exports @ webpack-dev-server.js:1 n.emit @ webpack-dev-server.js:1 s.add @ webpack-dev-server.js:1 r.ondata @ webpack-dev-server.js:1 t.exports @ webpack-dev-server.js:1 n.emit @ webpack-dev-server.js:1 r.onpacket @ webpack-dev-server.js:2 (anonymous function) @ webpack-dev-server.js:1 n.emit @ webpack-dev-server.js:1 r.onpacket @ webpack-dev-server.js:1 r.ondata.n @ webpack-dev-server.js:1 (anonymous function) @ webpack-dev-server.js:1 e.decodepayloadasbinary @ webpack-dev-server.js:1 e.decodepayload @ webpack-dev-server.js:1 r.ondata @ webpack-dev-server.js:1 (anonymous function) @ webpack-dev-server.js:2 n.emit @ webpack-dev-server.js:1 i.ondata @ webpack-dev-server.js:2 i.onload @ webpack-dev-server.js:2 i.create.hasxdr.n.onreadystatechange @ webpack-dev-server.js:2
index.html
<!doctype html> <html> <head> <title>basic property grid</title> <!-- include react --> <script src="./node_modules/react/dist/react-with-addons.js"></script> </head> <body> <div id="content"> <!-- root react component rendered --> </div> <!-- include webpack-dev-server script our scripts reloaded when make change --> <!-- we'll run webpack dev server on port 8090, make sure correct --> <script src="http://localhost:8090/webpack-dev-server.js"></script> <!-- include bundle contains our scripts, produced webpack --> <!-- bundle served webpack-dev-server, serve localhost:8090 --> <script type="text/javascript" src="http://localhost:8090/assets/bundle.js"></script> </body> </html>
bower.json
{ "name": "wonder", "version": "0.0.0", "description": "internal app", "main": "index.html", "authors": [ "and" ], "license": "mit", "ignore": [ "**/.*", "node_modules", "bower_components", "test", "tests" ], "devdependencies": { "jquery": "~2.1.4" } }
somewhere in source files or third-party libraries there reference resource named server
(without extension). in form of require('server')
. webpack trying best locate it. checks different forms of (e.g. server
directory, server.js
, server.jsx
, etc) in various locations fails in end. try find out reference is.
Comments
Post a Comment