0

I required one commonjs module with @rollup/plugin-commonjs plugin to build, my config:

plugins: [
   babel({
     exclude: 'node_modules/**',
     babelHelpers: 'bundled',
   }),
   resolve(),
   commonjs({
     transformMixedEsModules: true,
   }),
 ],

my commonjs code like this:

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Aegis=t()}(this, ()=>{})

after rollup build, the code is like this:

!function (e, t) {
    "object" == (_typeof(exports)) && "undefined" != 'object' ? module.exports = t() : (e = "undefined" != typeof globalThis ? globalThis : e || self).Aegis = t();
  }(undefined, function () {....

obviously, the moudle in statement "undefined" != _typeof(module) became "undefined" != 'object', when my umd js execute in browser, this is an error, module is not defined...

Browse other questions tagged or ask your own question.