How can I move my CommonJS project to ESM?
- Add "type": "module" to your package.json.
- Replace "main": "index.js" with "exports": "./index.js" in your package.json.
- Update the "engines" field in package.json to Node.js 14: "node": ">=14.16". (Excluding Node.js 12 as it's no longer supported)
- Remove 'use strict'; from all JavaScript files.
- Replace all require()/module.export with import/export.
- Use only full relative file paths for imports: import x from '.'; → import x from './index.js';.
- If you have a TypeScript type definition (for example, index.d.ts), update it to use ESM imports/exports.
- Optional but recommended, use the node: protocol for imports.