Git Product home page Git Product logo

Comments (3)

privatenumber avatar privatenumber commented on June 7, 2024 1

This is definitely unexpected.

What's happening is the first import statement gets converted to require(), and since require can't load Module (.mjs) files, it transforms them to CommonJS so it can be. The second dynamic import() remains untouched.

So the first and second files are technically different modules, where the first one is dynamically derived on demand.

This is a technical limitation but it will be resolved once nodejs/node#51977 lands

from tsx.

qraynaud avatar qraynaud commented on June 7, 2024

I understand that you keep the dynamic import, but since it’s using mts behind, it means that at some point tsx get to transpile it "again" right? So in this instance you do transpile it as an ESM module instead of as a CJS modules as the first time right? Could you not detect that it was previously loaded as a CJS and return the CJS version instead (since node do support import() on CJS files)? Or return to node a fake module that does export the required CJS module?

Even waiting for nodejs/node#51977 would not really resolve the issue since this patch does not support requiring modules with top level async in them.

Replacing the import() with a require() implicitely would end badly for a lot of files.
And if you replace it with a try/catch to fallback to import(), then the bug I'm reporting would still be there for those.

from tsx.

privatenumber avatar privatenumber commented on June 7, 2024

I'm not sure, but feel free to give it a tackle. I'd be happy to review the PR!

from tsx.

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.