Giter VIP home page Giter VIP logo

Comments (3)

edoardocavazza avatar edoardocavazza commented on May 25, 2024

Hello @bashmish, thank you for the issue and sorry for the delay.

I'm not sure if I understood the problem correctly. Indeed, the typings of @parcel/source-map suggest a default export of SourceMap, but this is not true on the implementation side.

As you can see here: link, the module exports the class like this:

exports.default = NodeSourceMap;

But it should be:

exports = NodeSourceMap;

in order for the class to be imported as the default member.

As you mentioned, we prefer Node with ESM, so I'm wondering if there's some scenario where the import is modified by a transpiler. Could you provide a reproduction case for us to investigate?

Nevertheless, we are certainly available to handle the scenario as soon as we understand it :)

from rna.

bashmish avatar bashmish commented on May 25, 2024

@edoardocavazza I ran into similar issues just yesterday, so good timing, since it gave me more knowledge to answer :)

Indeed there is a transpiler somewhere which dynamically patches ESM modules to be consumed by CommonJS modules. I don't know exactly how to solve it yet, I might still require a fix on your side, but for the time being I'll close this issue. Thank you so far!

from rna.

bashmish avatar bashmish commented on May 25, 2024

I'd like to reopen this.

Did a bit more digging into this problem and found out it's the well-known issue with default exports CJS/ESM interop which can't be solved by tools automatically in all cases.

There is a good explainer here https://esbuild.github.io/content-types/#default-interop

In my case I end up having The Babel interpretation somewhere in my toolchain. It's hard to pin-point where exactly as I have multiple layers of tools, which I don't always control, but I tried to play with configs after learning the heuristics that esbuild uses when choosing either The Babel interpretation or The Node interpretation, yet I couldn't make it work with current estransform published code.

In your case the The Node interpretation takes place and that requires you use this code:

import sourceMapDefault from '@parcel/source-map';
const { default: SourceMapNode } = sourceMapDefault;

This is a good workaround for apps, but for libs I think there is a better one which can solve it both for you and me. On top of that the TypeScript required you to copy over some types into packages/estransform/modules.d.ts from @parcel/source-map which can also be improved.

This problem and workarounds for it are also discussed in this esbuild issue.

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.