[英]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.