简体   繁体   English

TypeError: __webpack_require__(...).context 不是 function - 硬编码但不带参数

[英]TypeError: __webpack_require__(…).context is not a function - Works hardcoded but not with parameter

const importAll = (r) => r.keys().map(r);
const importAllFrom = (dir) => importAll(require.context(dir, false, /\.(png|jpe?g|svg)$/))

Calling `importAllFrom("../images") throws an error 'webpack_require__(...).context is not a function'.调用 `importAllFrom("../images") 会引发错误 'webpack_require__(...).context is not a function'。

However the following code where I hardcode the directory name works just fine.但是,我对目录名称进行硬编码的以下代码可以正常工作。

const importAll = (r) => r.keys().map(r);
const importAllFrom = (dir) => importAll(require.context("../images", false, /\.(png|jpe?g|svg)$/))

All the code is in the same react component.所有代码都在同一个反应组件中。

Am I missing something really silly??我错过了什么真的很傻吗?

It didn't actually cross my mind to check the docs for this problem because 99% of the time this sort of problem is a typo but actually they state that this is how it's supposed to work:我实际上并没有想到检查这个问题的文档,因为 99% 的时间这类问题是一个错字,但实际上他们 state 这就是它应该如何工作的:

The arguments passed to require.context must be literals!传递给 require.context 的 arguments 必须是文字!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:__webpack_require__(...).context 不是 function - Uncaught TypeError: __webpack_require__(...).context is not a function __webpack_require__(...).context 不是 function - __webpack_require__(...).context is not a function 诊断未捕获的TypeError:__webpack_require __(…).createServer不是函数? - Diagnosing Uncaught TypeError: __webpack_require__(…).createServer is not a function? 为什么webpack向'__webpack_require__'函数添加属性? - Why webpack add properties to '__webpack_require__' function? 未捕获的类型错误:无法读取 __webpack_require__ 处未定义的属性“调用” - Uncaught TypeError: Cannot read property 'call' of undefined at __webpack_require__ React - ssh2 模块错误:未捕获的类型错误:__webpack_require__(...).constants 未定义 - React - ssh2 module Error: Uncaught TypeError: __webpack_require__(…).constants is undefined 在 __webpack_require__ 中的 NextJS 中构建错误 - Build errors in NextJS in __webpack_require__ 未在反射元数据上定义需求-__webpack_require__问题 - Require is not defined on reflect-metadata - __webpack_require__ issue 未捕获的类型错误:__webpack_require__.r 不是函数 - Uncaught TypeError: __webpack_require__.r is not a function 未捕获的类型错误:__webpack_require__.e 不是 function - Uncaught TypeError: __webpack_require__.e is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM