ECMAScript first
Packemon utilizes the
babel-plugin-cjs-esm-interop plugin to
transform ECMAScript module code (ESM) to CommonJS code (CJS) and vice versa. However, it's much
easier to transform from ESM to CJS, as async code (import()) can be translated to non-async code
(require()) without issue, but the reverse is not possible.
Because of this, we suggest writing all source code in ESM (.mjs, .ts, .tsx, .js with
module type). Modules are the future, so start using them today!
Requirements
- Use
importorimport()instead ofrequire(). - Use
export constorexport {}instead ofexports.<name>. - Use
export defaultinstead ofmodule.exports. - Use
import.meta.urlinstead of__filenameand__dirname. - Use
module.createRequire()or theresolvepackage instead ofrequire.resolve(). - Do not use
require.extensionsorrequire.cache. - Do not use
process.env.NODE_PATH.
For a full list of changes, view the official Node.js documentation.