Giter Club home page Giter Club logo

Comments (1)

privatenumber avatar privatenumber commented on June 28, 2024 2

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)

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.