I'm working on my first full stack app (it's a simple note app) and I'm getting this warning when I bundle webpack:
WARNING in ./node_modules/express/lib/view.js 81:13-25 Critical dependency: the request of a dependency is an expression @ ./node_modules/express/lib/view.js @ ./node_modules/express/lib/application.js @ ./node_modules/express/lib/express.js @ ./node_modules/express/index.js @ ./routes/server.js
Here is my webpack.config.js
file:
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const config = {
entry: {
app: './routes/server.js'
},
output: {
path: __dirname + "/public",
filename: 'build/bundle.js'
},
module : {
rules : [
{
test : /\.jsx?/,
loader : 'babel-loader',
exclude: /node_modules/,
query: {
"presets" : ["es2015", "react"]
}
}
]
},
target: 'node',
externals: [nodeExternals({
whitelist: ['express', 'mongodb', 'body-parser', 'react', 'react-dom', 'random-color']
})]
};
module.exports = config;
Here's my package.json
file:
{
"name": "quick-notes-app",
"version": "1.0.0",
"description": "my first full-stack javascript app",
"main": "./routes/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon --exec babel-node ./routes/server.js --ignore public/",
"dev": "webpack -wd",
"lint": "eslint ./"
},
"repository": {
"type": "git",
"url": "git+https://github.com/CandiW/quick-notes-app.git"
},
"author": "CandiW",
"license": "ISC",
"bugs": {
"url": "https://github.com/CandiW/quick-notes-app/issues"
},
"homepage": "https://github.com/CandiW/quick-notes-app#readme",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.3",
"mongodb": "^2.2.35",
"randomcolor": "^0.5.3",
"react": "^16.3.2",
"react-dom": "^16.3.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.7.0",
"nodemon": "^1.17.3",
"webpack": "^3.11.0",
"webpack-node-externals": "^1.7.2"
}
}
I installed webpack-node-externals
as I had been getting several errors and warnings from webpack. I determined at that point that webpack was not ignoring the node_modules
although I have node_modules
in exclude
.
I'm unsure what I'm doing wrong or if I am doing anything wrong?? If anyone has any ideas on how to fix, please help! You can also find my github repo for this project here: Quick-Notes-App
Its worked for me. i changed code in webpack.server.config.js yours may be webpack.config.js or webpack.server.js ...etc
.... webpack config...
..from...
entry:{...},
output: {
path: path.join(__dirname, '..', 'build'),
publicPath: '/',
libraryTarget: "commonjs2"
},
target: 'node',
to
entry:{...},
output: {
path: path.join(__dirname, '..', 'build'),
publicPath: '/',
libraryTarget: "commonjs2"
},
target: 'node',
externals: {
express: 'express',
},
just add below code ( same for other modules )
externals: {
express: 'express',
},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.