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
import
orimport()
instead ofrequire()
. - Use
export const
orexport {}
instead ofexports.<name>
. - Use
export default
instead ofmodule.exports
. - Use
import.meta.url
instead of__filename
and__dirname
. - Use
module.createRequire()
or theresolve
package instead ofrequire.resolve()
. - Do not use
require.extensions
orrequire.cache
. - Do not use
process.env.NODE_PATH
.
For a full list of changes, view the official Node.js documentation.