Webpack includes AMDPlugin by default, so if a module checks for AMD before CommonJS, that module definition will be used.
if (typeof define === \'function\'
It can be solved with imports-loader
There are many modules that check for a define function before using CommonJS. Since webpack is capable of both, they default to AMD in this case, which can be a problem if the implementation is quirky. Then you can easily disable the AMD path by writing
imports?define=>false
Simply do
require('imports?define=>false!myjsfile.js')
OR a better approach is in webpack.config.js you add a loader
loaders: [ { test: /myjsfile.js/, loader: 'imports?define=>false'} ]
You can also add to the following to your rules to disable AMD(webpack 2+):
module: {
rules: [
{ parser: { amd: false } }
]
}
From: https://webpack.js.org/configuration/module/
Also consider script-loader, as mentioned at the end of the Shimming documentation:
The script-loader evaluates code in the global context, similar to inclusion via a script tag. In this mode, every normal library should work. require, module, etc. are undefined.