Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

404
Views
Can't figure out how to use webpack's require.context()

I have an AngularJS with webpack project, and I want to import all the .js files in my project to webpack without adding the path of each file individually, so on the webpack docs I found this require.context() and it looked straight forward, but for some reason I keep getting this error:

webpackEmptyContext(req) {
    var e = new Error("Cannot find module '" + req + "'");
    e.code = 'MODULE_NOT_FOUND';
    throw e;
}

This is how the function is declared, I used the same example that they gave on the docs:

function importAll(r) {
  console.log(r)
  r.keys().forEach(r);
}

importAll(require.context('./src', true, /\.js$/));

I'm using node 10 and webpack 5.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The path argument in the require.context call is relative to your file that declared the function. If the file that calls require.context is deep in your src directory, you may try locating your src directory by something like ../../../../src and put this string into the argument.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!