Uncaught TypeError: __webpack_require__(…).context is not a function
See original GitHub issueBug report
What is the current behavior?
When I am trying to import dynamically vue components using this code:
const components = require.context(‘./’, true, ‘/^index.js$/’); I am getting this error:
app.js:9 Uncaught TypeError: webpack_require(…).context is not a function at Module…/asset/app.js (app.js:9) at webpack_require (bootstrap:782) at fn (bootstrap:150) at Object.0 (app.293d5fe1d8a073fed37a.bundle.js:1747) at webpack_require (bootstrap:782) at checkDeferredModules (bootstrap:45) at bootstrap:858 at bootstrap:858
Why is that? How to fix that? What have I missed?
If the current behavior is a bug, please provide the steps to reproduce.
Just open your empty js-file and add next line of code:
const components = require.context(‘./’, true, ‘/^index.js$/’);
The error which I was getting is located in the browser console.
What is the expected behavior? The expected behavior is an absence of error. I have read the documentation and did everything as was wrote in the documentation.
Other relevant information: webpack version: webpack@4.34.0 Node.js version: v11.15.0 Operating System: Linux, Debian Additional tools:
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (1 by maintainers)

Top Related StackOverflow Question
I also experienced this issue when using a variable as the first param.
FAILED
WORKING
Any explanation as to why this may be?
@minlare I just had the same issue. I was trying to pass the path via variable, but received the above mentioned error. The trick is that the path parameter must be a literal. And as far as I understand how the compiler works, the path must be a literal regex, because the compiler has to find these files to add them in the compiled code, as JavaScript doesn’t have access to the file system.
Passing the path via variable wouldn’t work, because the compiler can’t know what kind of path will you give him and can’t prepare the required files during compile time.