Giter Club home page Giter Club logo

Comments (12)

 avatar commented on May 4, 2024

@guybedford Thanks for your time on this stuff, as always. :)

Might the best solution actually be to revisit babel/babel#2148? Or I'm I wrong in thinking that the algorithm you described there would solve this issue and all others like it? Regardless, it seems to me like there must be some way to determine whether a module was originally ES6, and if so and if it's imported into a CJS module (or another transpiled ES6 module with default specified of course), then use the default rather than the entire ES6 module object.

from babel-plugin-react-transform.

guybedford avatar guybedford commented on May 4, 2024

@timbur sure no problem, it's a good use case to cover.

I think the issue here is actually just that the file.addImport API call to Babel needs to access the default export to be like import x from 'x' instead of import * as x from 'x' for correct interop, which should then handle the use case completely fine. This may or may not be a Babel issue underneath, I'm not completely sure yet.

from babel-plugin-react-transform.

gaearon avatar gaearon commented on May 4, 2024

When you come to a conclusion let me know and I'll happily add a workaround you think is right.

from babel-plugin-react-transform.

 avatar commented on May 4, 2024

I think the issue here is actually just that the file.addImport API call to Babel needs to access the default export to be like import x from 'x' instead of import * as x from 'x' for correct interop

Ohh I see. That makes the most sense and could be exactly the problem.

from babel-plugin-react-transform.

guybedford avatar guybedford commented on May 4, 2024

Sure thanks, I've posted babel/babel#2496.

from babel-plugin-react-transform.

guybedford avatar guybedford commented on May 4, 2024

Just to update here - apparently addImport isn't a public API. The issue here is definitely with that function not handling the interop scenarios.

from babel-plugin-react-transform.

gaearon avatar gaearon commented on May 4, 2024

I think that actually if I use file.addImport directly (effectively reverting d4c90c7) it will work as you described. Can you confirm this is the change you need?

from babel-plugin-react-transform.

 avatar commented on May 4, 2024

@gaearon No, it still imports the entire module object rather than the default.

Actually, hold on...

from babel-plugin-react-transform.

 avatar commented on May 4, 2024

I thought maybe I could use a JSPM override to make it work but no, d4c90c7 definitely breaks it by importing the entire module object rather than the module's default export.

from babel-plugin-react-transform.

gaearon avatar gaearon commented on May 4, 2024

So will reverting it help? I can do that.

from babel-plugin-react-transform.

 avatar commented on May 4, 2024

Yeah reverting it to match my PR fixed the problem for me.

from babel-plugin-react-transform.

gaearon avatar gaearon commented on May 4, 2024

I think this is probably fixed because we no longer use absolute in the source.
Please reopen if still an issue.

from babel-plugin-react-transform.

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.