- BigInt literals (15n) are not supported in some environments
- Must use BigInt('15') instead
- It was not supported in React Native 0.70. Need to test in new versions
- Must use hybrid ESM-Common.js package
- ESM (ECMAScript modules) are not supported in Electron, Jest
- Electron needs pre-compilation step aka bundler
- Jest has experimental esm flag, also can be replaced with micro-should
- Common.js modules (legacy node.js modules) are not supported in browsers, Deno
- Browsers can be worked around with UMD wrapper
- Doesn’t play well with ESM in-browser imports
- ESM (ECMAScript modules) are not supported in Electron, Jest
- Must use full extensions inside of library imports
- file a.ts imports b.ts
- .ts imports are not allowed in js/node/browser
- file a.ts imports b.js
- js/node/browser works, deno doesn’t
- file a.ts imports b.ts
- (Fixed in React Native 0.72) Can’t place compiled files in “lib” (or any other) directory, need to place in root
- Example: can’t do
lib/hash.js
, need to place inhash.js
- Otherwise React Native will fail: facebook/metro#670
- package.json modules can’t solve it
- Example: can’t do
- Cryptography imports need import maps
- Can’t use
globalThis.crypto
in node.js older than v19 - Can’t use node.js
require(‘crypto’)
in browsers or bundlers
- Can’t use
Last active
February 10, 2024 17:45
-
-
Save paulmillr/cf5f8441c93dfef87c814af18a06d166 to your computer and use it in GitHub Desktop.
Why writing hybrid Common.js + ESM NPM packages is hard
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment