Code Monkey home page Code Monkey logo

Comments (6)

suntong avatar suntong commented on July 29, 2024

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.

suntong avatar suntong commented on July 29, 2024

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.

suntong avatar suntong commented on July 29, 2024

Migrating

There are two ways to move your packages to ESM:

  1. 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.
  2. Dual --- ESM with a build step that transpiles a CommonJS fallback
    This requires you to also set up a build step and add a exports 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.

huan avatar huan commented on July 29, 2024

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.

suntong avatar suntong commented on July 29, 2024

you can use either import or require for our package.

👍👍👍

from tsconfig.

suntong avatar suntong commented on July 29, 2024

you can use either import or require for our package

I tried, but one works and one doesn't.
the two code is almost the same. Here are the key changes:

image

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.