Comments (3)
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.
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.
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)
- Is Bundle / Compile command planned? HOT 1
- Regression with MikroORM introduced with tsx v4.9.1 HOT 2
- Regression in 4.9.1 – Cannot find module (…) Did you mean to import "….js"? HOT 2
- Modules imported dynamically from an absolute path are not loaded/handled by tsx v4.9.1 HOT 3
- 💅 Logo early preview and feedback
- `node:assert`'s `assert.ok(false)` is really slow when using tsx HOT 5
- Unexpected `top-level await error` for `type: module` + top level await in `node_modules` HOT 1
- [ESM / Node v22] Broken import of a correctly bundled library HOT 3
- Incompatible with `import-in-the-middle` loader HOT 4
- Parsing error when using variable `of` HOT 7
- Cannot be used with Nuxt HOT 5
- c8 incorrectly reports 100% coverage when using tsx HOT 2
- tsx fails to find aliased imports from workspace dependencies HOT 2
- Is this for Typescript or not?
- All first lines uncovered when using `c8` with `tsx --test` HOT 3
- support for webstorm plugins? HOT 2
- Watcher continues to watch files after removal as dependency (dead imports)
- tsx should come first when chaining loaders
- ERR_UNKNOWN_FILE_EXTENSION with `import 'tsx'`, but `--import tsx` works HOT 4
- Support `customConditions` in `tsconfig.json`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tsx.