Critical dependency: the request of a dependency is an expression

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中的鏈接寫法不對等等

以上

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容