question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Bug 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:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

38reactions
minlarecommented, Aug 22, 2019

I also experienced this issue when using a variable as the first param.

FAILED

const path = './path/';
const components = require.context(path);

WORKING

const components = require.context('./path/');

Any explanation as to why this may be?

16reactions
papa-zulucommented, Aug 26, 2019

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: __webpack_require__(…).context is not ...
Try changing the third argument from a string to a regex, ie: const components = require.context('./', true, /^index.js$/).
Read more >
TypeError: require.context is not a function · Issue #2487
Hi guys, Issue details If you use require.context within a React component the storyshots will fail with TypeError: require.context is not a ......
Read more >
How to resolve “TypeError: require.context is not a function” in ...
While we were writing Jest tests, we ran into an the error “TypeError: require.context is not a function”. This is because of the...
Read more >
Dependency Management - webpack
You can create your own context with the require.context() function. It allows you to pass in a directory to search, a flag indicating...
Read more >
[webpack问题]TypeError: __webpack_require__(...).context is ...
[webpack问题]TypeError: __webpack_require__(...).context is not a function. 三知之灵 已于 2022-04-15 02:39:45 修改 2421 收藏 1.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found