Comments (6)
Howto
Thanks for providing all those informative links for us to read @huan, So
Switching the default from CJS to ESM would be a big break in backwards compatibility. ...
CJS can’t require() ESM because of top-level await
Would you explain just in high level what your strategy is please @huan? Especially, are you going to follow the recommendation to
Provide a CJS version of your library
Thanks!
from tsconfig.
I meant, this is how I've been consuming wechaty in my plain JavaScript app:
const {
Wechaty,
ScanStatus,
log,
} = require('wechaty')
And I presume lots of JavaScript developers are doing the same thing as well.
Would you explain just in high level what your strategy is please
At the very least, what we JavaScript developers should do, after such transition is finished? Hopefully "Dual-ESM-CJS-module" means that we can still use our existing scripts without huge alternations. thx.
from tsconfig.
Migrating
There are two ways to move your packages to ESM:
- Pure ESM
This has the benefit that it's easier to set up. You just add"type": "module"
to your package.json, require Node.js 12, update docs & code examples, and do a major release.- Dual --- ESM with a build step that transpiles a CommonJS fallback
This requires you to also set up a build step and add aexports
field to your package.json. Read more
Note that there are many downsides.Personally, I plan to do
1
as I think it's better to rip off the bandaid and push the ecosystem forward.
(taken from https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77 which is now gone but mirrored at here)
Hmm..., maybe it is time to take plan #1
... See:
https://ar.al/2021/01/27/commonjs-to-esm-in-node.js/
from tsconfig.
Yes, the ESM is the future and we should take it as soon as possible.
However, for maximum compatibility and a better developer experience, the Wechaty community strategy is to build a Dual-CJS-ESM package, which is what this issue is tracking about: you can use either import
or require
for our package.
from tsconfig.
you can use either
import
orrequire
for our package.
👍👍👍
from tsconfig.
you can use either
import
orrequire
for our package
I tried, but one works and one doesn't.
the two code is almost the same. Here are the key changes:
and now it is working. Ref padlocal/wechaty-puppet-padlocal-demo#16
So I'd conclude that the ESM module support is still broken, unfortunately.
from tsconfig.
Related Issues (6)
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 tsconfig.