0
votes

I'm using NodeJs and ReactJs, with webpack config.

When I build my app, I have an error on navigator console :

Require is not defined

module.exports = require("jquery");

So I tried to import RequireJs, like this :

var requirejs = require('requirejs');

requirejs.config({  
    nodeRequire: require,
}),

requirejs (['jquery'])

But I have the same error.

Is there any way to solve the problem?

2
Is your webpack target web ? ref - Gabriel Bleu
My webpack target node, as you can see in my anwer comment - Anaïs Saez

2 Answers

0
votes

You're trying to use a CommonJS module from within your browser. This will not work.

ref

Try setting webpack target to web.

-1
votes
module.exports = {

    target: 'node',
    //externals: [nodeExternals()],

    [...]
};