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

jaesung2061 picture jaesung2061  路  3Comments

unindented picture unindented  路  3Comments

yannispanousis picture yannispanousis  路  3Comments

adjavaherian picture adjavaherian  路  3Comments

IngwiePhoenix picture IngwiePhoenix  路  3Comments