Cannot set property 'esprima' of undefined at webpackUniversalModuleDefinition

940 Views Asked by At

I'm receiving this error:

Uncaught TypeError: Cannot set property 'esprima' of undefined at webpackUniversalModuleDefinition (esprima.js:11) at esprima.js:12

When trying to load a web app:

Screenshot

The error happens here:

(function webpackUniversalModuleDefinition(root, factory) {
/* istanbul ignore next */
    if(typeof exports === 'object' && typeof module === 'object')
        module.exports = factory();
    else if(typeof define === 'function' && define.amd)
        define([], factory);
/* istanbul ignore next */
    else if(typeof exports === 'object')
        exports["esprima"] = factory();
    else
        root["esprima"] = factory(); // ** => error is thrown here
})(this, function() {

// ...

});

For reference, the file webpack.config.js is:

// webpack.config.js
module.exports = {
    entry: {
        // import: './src/Three.js'
    },
    mode: 'production',
    output: {
        path: __dirname,
        publicPath: '/',
        filename: './build/three.min.js'
    },
    devServer: {
        watchContentBase: true,
        publicPath: "/",
        contentBase: "./",
        hot: true,
        port: 9090,
    },
};

Can anyone provide a clue what might be wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

The error is resolved by using WebPack script-loader which loads as simple script rather than module:

https://v4.webpack.js.org/loaders/script-loader/