Critical dependency: the request of a dependency is an expression
vue-cli 引入jsdom 編譯問題如下
// error
warning in ./node_modules/jsdom/lib/jsdom/utils.js
166:4-31 Critical dependency: the request of a dependency is an expression
warning in ./node_modules/jsdom/lib/jsdom/utils.js
172:19-38 Critical dependency: the request of a dependency is an expression
剛剛熟悉Vue,對這些error一頭霧水,網(wǎng)絡(luò)搜索大半天
解決此問題的解決辦法如下向webpack.base.conf.js文件中添加以下配置
//解決Critical dependency: require function is used in a way in which dependencies cannot be statically extracted的問題
unknownContextCritical : false,
//解決the request of a dependency is an expression
exprContextCritical: false,
中間遇到的彎路
我首先去了jsdom的github,然后搜索
Critical dependency: the request of a dependency is an expression
關(guān)鍵字,找到了此問題
https://github.com/jsdom/jsdom/issues/2066
文章中提到了用 webpack-node-externals
const nodeExternals = require('webpack-node-externals');
module.exports = {
externals: [nodeExternals()],
// etc configs here
}
確實不報這個錯誤了,但是web啟動后,頁面加載不出來,報了另外的request is not defined的錯誤
另外搜索到其他解決辦法的基本都是說關(guān)鍵字沖突,require中的鏈接寫法不對等等
以上