当前位置:首页 > Web开发 > 正文

因此自己记录下

2024-03-31 Web开发

标签:

错误描述

凡是问题常呈此刻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:该方案是在度娘中找到的,并非原创,苦于已经找不到原文,因此本身记录下,以便于下次遇到问题时便利查找)

Webpack打包时呈现require报错问题

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30130.html