Coder Social home page Coder Social logo

Comments (5)

edoardocavazza avatar edoardocavazza commented on June 18, 2024

Hello @ruanyl!

I don't think you need the commonjs plugin for your use case since you are using the bundle: true option without externals.

Esbuild itself should bundle commonjs dependencies and export React as default specifier. In fact, at the end of the out.js file I can see the statement:

export default require_react();

Do you have a different output?

from rna.

ruanyl avatar ruanyl commented on June 18, 2024

@edoardocavazza Thanks for your reply :) I probably had some misunderstandings of the use-case of commonjs plugin.

Yes, I have React exported as default, but the problem with esbuild forma: 'esm' is it didn't create export for named exports, such as useCallback, useMemo, etc.

What I'm trying to do is compile React to native ESM so that I can use it directly in the browser without bundling it.

from rna.

edoardocavazza avatar edoardocavazza commented on June 18, 2024

You understood it correctly, but there are were two problems here.

The first one is was a bug 😅 I should have addressed it with the 0.12.39 version. Thank you for reporting!

The second one is a "design" choice: the commonjs plugin can transform module.exports.something to export const something, the problem here is that the React entrypoint exposes the whole module to module.exports.
AFAIK, even Node loads this kind of modules using default specifier, so I intended the plugin this way.

BUT, you can try to change the entrypoint to "./node_modules/react/cjs/react.development.js", which correctly assigns named references to the module.exports.

from rna.

edoardocavazza avatar edoardocavazza commented on June 18, 2024

Hi @ruanyl , have you managed to create an ESM-based React package? Can we close this issue?

from rna.

ruanyl avatar ruanyl commented on June 18, 2024

@edoardocavazza Yep, thanks for the help, closing now :)

from rna.

Related Issues (20)

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.