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一头雾水,网络搜索大半天
解决此问题的解决办法如下向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
关键字,找到了此问题
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的错误
另外搜索到其他解决办法的基本都是说关键字冲突,require中的链接写法不对等等
以上
网友评论