Coder Social home page Coder Social logo

Idea: Add a way to invoke from cli about cjs-es HOT 5 OPEN

eight04 avatar eight04 commented on September 17, 2024
Idea: Add a way to invoke from cli

from cjs-es.

Comments (5)

eight04 avatar eight04 commented on September 17, 2024

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.

eight04 avatar eight04 commented on September 17, 2024

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.

karfau avatar karfau commented on September 17, 2024

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.

eight04 avatar eight04 commented on September 17, 2024

With typescript, you should probably write es import/export in ts source code and compile them into es/cjs modules.

from cjs-es.

karfau avatar karfau commented on September 17, 2024

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)

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.