Webpack: Got error when using require.context

Created on 16 Nov 2015  路  3Comments  路  Source: webpack/webpack

I got an error

var req = require.context(path.join(ROOT, "src/pages"), false, /^\.\/.*\.js$/);
                  ^

TypeError: require.context is not a function

and I am on [email protected] [email protected]

Any idea on how to resolve this?

Thanks,

Hao

question

Most helpful comment

require.context(path.join(ROOT, "src/pages"),

You can't use an expression as first argument to require.context. It must be a compile-time constant string.

All 3 comments

Can you provide a little test case? It's easier to figure out what's going on that way.

Why does that seem that you are trying to use require.context in an unbundled file?

Basically, did you compile your code or did you try running it raw? webPack does not modify require at all - it only transpiles it's usage within the bundle during compilation.

Would be nice if you could provide a bit more detail on your scene. :)

require.context(path.join(ROOT, "src/pages"),

You can't use an expression as first argument to require.context. It must be a compile-time constant string.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dubrowgn picture dubrowgn  路  3Comments

zerkalica picture zerkalica  路  3Comments

Tjorriemorrie picture Tjorriemorrie  路  3Comments

abergs picture abergs  路  3Comments

olalonde picture olalonde  路  3Comments