Skip to content

module

@babel/plugin-transform-runtime will always emit _interopRequireDefault.

Heres the problem, when using commonjs resolution mixes with es-module resolution, chaos may happen.

image-20220728142025513

image-20220728142054281

Notes that img2 imports the pkg from img1. And without the commented line _interopRequireDefault2 = _interoRequireDefault2.default, error _interopRequireDefault2 is not a function will be throwed, which is a common one of babel. Form my point of view, its because the 'commonjs version' of interopRequireDefault take place the original 'es version' of interopRequireDefault.

best practice

For bowser/node enviroment

package.json:

{
  "main": "./lib/index.js",
  "module": "./es/index.js",
}

with /dist(umd) 、/es、/lib

{
   "main": "lib/Server.js",
}

others

It seems that only export commonjs version is fine

*var* _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(*exports*, "__esModule", {
  value: true
});