https://github.com/baymac/esm-cjs-interop
This repo demonstrates using both esmjs and cjs in your node project. Usually needed for migration.
https://github.com/baymac/esm-cjs-interop
Last synced: over 1 year ago
JSON representation
This repo demonstrates using both esmjs and cjs in your node project. Usually needed for migration.
- Host: GitHub
- URL: https://github.com/baymac/esm-cjs-interop
- Owner: baymac
- Created: 2021-05-20T19:57:57.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-20T20:08:50.000Z (about 5 years ago)
- Last Synced: 2025-01-23T01:23:34.721Z (over 1 year ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node JS ESM and CJS Interop Demo
## Pre-requisites
Node >= 13.2.0 (ships with ECMASscript Modules)
## Project Structure
If you wish to add ESMJS support to your Common JS node project, you can do it in 2 ways. This repo contains 2 nodejs projects to demonstrates both ways:
1. `cjs-default`: Demonstrates how to use ES modules in a CJS project (all \*.js files are default treated as CJS). package.json contains `"type": "commonjs"`.
1. `esm-default`: Demonstrates how to use CJS modules in a ESMJS project (all \*.js files are default treated as ESMJS). package.json contains `"type": "module"`.
Both projects have 2 test files:
1. `testCjs` - Written in CJS to show how to load ES modules. Run with `npm run cjs`.
2. `testEsm` - Written is ESMJS to show how to load CJS modules. Run with `npm run esmjs`
## References
- https://nodejs.medium.com/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663
- https://nodejs.org/api/modules.html
- https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/