![](/img/trans.png)
[英]Critical dependency: the request of a dependency is an expression webpack svelte
[英]Webpack WARNING in ./node_modules/express/lib/view.js Critical dependency: the request of a dependency is an expression
我正在開發我的第一個完整堆棧應用程序(它是一個簡單的筆記應用程序),當我捆綁 webpack 時收到此警告:
./node_modules/express/lib/view.js 81:13-25 中的警告:關鍵依賴項:依賴項的請求是一個表達式 @ ./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
這是我的webpack.config.js
文件:
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;
這是我的package.json
文件:
{
"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"
}
}
我安裝了webpack-node-externals
因為我從 webpack 收到了幾個錯誤和警告。 我當時確定 webpack 沒有忽略node_modules
盡管我在exclude
有node_modules
。
我不確定我做錯了什么,或者我做錯了什么? 如果有人對如何修復有任何想法,請幫助! 你也可以在這里找到我的這個項目的 github 倉庫: Quick-Notes-App
它對我有用。 我更改了 webpack.server.config.js 中的代碼,你的可能是 webpack.config.js 或 webpack.server.js ...等
.... webpack 配置...
..from...
entry:{...},
output: {
path: path.join(__dirname, '..', 'build'),
publicPath: '/',
libraryTarget: "commonjs2"
},
target: 'node',
到
entry:{...},
output: {
path: path.join(__dirname, '..', 'build'),
publicPath: '/',
libraryTarget: "commonjs2"
},
target: 'node',
externals: {
express: 'express',
},
只需添加以下代碼(其他模塊相同)
externals: {
express: 'express',
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.