__webpack_require__(...).context 不是函数

Dou*_*Dou 6 javascript webpack

我越来越

index.js:978 TypeError: __webpack_require__(...).context is not a function
at eval (index.vue:20)
at Object.dqAR (pages-investment-pages-home-index.js:348)
at __webpack_require__ (index.js:854)
at fn (index.js:151)
at eval (null:1)
at Module.Hi1e (pages-investment-pages-home-index.js:177)
at __webpack_require__ (index.js:854)
at fn (index.js:151)
at eval (null:1)
at Module.bE2I (pages-investment-pages-home-index.js:320)
Run Code Online (Sandbox Code Playgroud)

这是我的代码

const path = './'
require.context(path,false,/\.js$/)
Run Code Online (Sandbox Code Playgroud)

看起来 require.context 的参数不能是变量。因为当我这样使用时它工作正常:

require.context('./',false,/\.js$/)
Run Code Online (Sandbox Code Playgroud)

我对此感到困惑。

是因为这个函数属于 webpack 并且它在编译之前运行吗?

谢谢你的回答。

Ami*_*mir 8

传递给的参数require.context 必须是文字!(查看链接中的警告)

在下图中,右侧是左侧生成的 webpack:

使用文字生成有效的__webpack_require__在 require.context 中使用文字

使用变量生成无效__webpack_require__在 require.context 中使用变量


归档时间:

查看次数:

4191 次

最近记录:

4 年,4 月 前