Comments (1)
Thanks for the bug report @JounQin
tsx supports loading ESM in Node's CommonJS mode by compiling it to CommonJS syntax... so if a module file (.mjs or package.json#type: 'module'
) gets require()
'd, it gets converted to CommonJS. Since require()
is sync, it cannot handle top-level await. Basically, this is the same limitation as the recent improvement in Node: nodejs/node#51977
Looking at Prettier's code, it looks like it tries require()
first, and if it fails, it tries import()
. Because we want it to go to import()
(which supports TLA), you can opt-in only to the ESM enhancement:
node --import tsx/esm scripts/test
This way, the require()
will fail, and skip to the import() and the TLA file will get loaded expectedly.
Since it catches the ERR_REQUIRE_ESM
error, it might be a good idea to make tsx emit that instead of or in addition to the TLA error.
By the way, if you have any sway in how Prettier loads the config files, the new tsImport()
function might be useful for supporting TypeScript configs.
It's being experimented in ESLint via eslint/eslint#18440
from tsx.
Related Issues (20)
- Typescript REPL HOT 1
- Multiline input in Typescript REPL
- Feature request: Extend 'tsx watch' for run command on detects file changes HOT 2
- Parse error when using classes and complicated hashbangs
- Script not running when node=21, type="module", watchmode is enabled, is importing from "node:process" and using turborepo HOT 1
- Support `--input-type=ts` HOT 2
- tsx can't run code with endent HOT 3
- 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
- [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
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.