Uncaught TypeError: __webpack_require__(…).context is not a function

Try changing the third argument from a string to a regex, ie:

const components = require.context('./', true, /^index.js$/)

I have usages with regexes which work, and others which I'm trying to sort out, which don't use an inline regex like this one.

Side-note: you're asking to find everything from './' downward (recursive: you're setting that flag to true), but will only accept one file: index.js in the base folder. If that's all you want, I'd suggest changing the recursive flag to false -- it will be quicker.


doc link

there is a sentence The arguments passed to require.context must be literals in docs. The third argument should be a literals like /^index.js$/. I got the same error when I used new RegExp()