Comments (5)
If you use rollup, try output.preserveModules
option with rollup-plugin-cjs-es.
A potential issue: if your module uses external libraries, those libraries may provide different entries for esm/cjs. You may have to tell the plugin how to import those external libraries. More details: https://github.com/eight04/rollup-plugin-cjs-es#missing-exports-foo-is-not-exported-by-foojs
A CLI should still be nice. It can look into external libs to determine their singature, or even raise an error if the library doesn't support ESM. Before implementing our own solution, we should compare other alternatives first e.g.
from cjs-es.
BTW it may need a resolver to rewrite the module path. You don't need extension in cjs but it is required by ESM (i.e. ./foo
-> ./foo.mjs
or ./foo/index.mjs
)
from cjs-es.
Thank you for the additional details.
Another option might be to use typescript to convert the modules, https://blog.logrocket.com/publishing-node-modules-typescript-es-modules/ contains the basic concepts, here is the related typescript reference https://www.typescriptlang.org/docs/handbook/2/modules.html.
I think I'm currently leaning towards it, since we plan to generate types anyway.
You can decide yourself if you want to keep this issue open.
from cjs-es.
With typescript, you should probably write es import/export in ts source code and compile them into es/cjs modules.
from cjs-es.
With typescript, you should probably write es import/export in ts source code and compile them into es/cjs modules.
Of course that is the usual use case.
As the linked article shows, it's also possible to write code in commonjs and tell TS to write it's output as ES modules.
from cjs-es.
Related Issues (13)
- A more clever way to transform nested named exports without hoisting HOT 1
- Optimize nested module
- Array element could be null
- Failed with UMD wrapper?
- Change export type to default when `this` is used in the exported function
- require(APP_ROOT + '/foo') HOT 2
- Document nested option HOT 9
- Error when assigning exports to module.exports HOT 3
- Variable access before defined (named exports)
- Multiline var definition
- Super class is not a namespace
- Return import/export information HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cjs-es.