Webpack打包时出现require报错问题
错误描述
- 通常问题常出现在
target: ‘node‘
环境中 - 编译文件中存在以如下方式使用
require
:
// for example 1: const reload = require('require-reload')(requireFunc) // for example 2: function main () { var data = require(dataPath) }
- 打包时会报错:
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted Critical dependency: the request of a dependency is an expression
错误解决方案
- 在编译文件中添加如下代码即可:
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
(PS:该方案是在度娘中找到的,并非原创,苦于已经找不到原文,因此自己记录下,以便于下次遇到问题时方便查找)
相关推荐
yezitoo 2020-06-06
lei0 2020-11-02
webgm 2020-08-16
igogo00 2020-07-04
iconhot 2020-06-26
88481456 2020-06-18
疯狂紫萧 2020-06-16
SelinaChan 2020-05-15
luckymaoyy 2020-04-25
80437700 2020-04-17
austindev 2020-04-07
我有一只小松鼠 2020-02-29
binglingnew 2012-10-03
始作俑者 2020-01-19
jinxiutong 2020-01-04
Dawnworld 2019-12-23
yezitoo 2019-12-05
moyigg 2019-12-02