Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonJS module output broken after updating from 5.5.4 to 5.6.2 #59991

Open
SBoudrias opened this issue Sep 17, 2024 · 4 comments
Open

CommonJS module output broken after updating from 5.5.4 to 5.6.2 #59991

SBoudrias opened this issue Sep 17, 2024 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@SBoudrias
Copy link

SBoudrias commented Sep 17, 2024

🔎 Search Terms

5.6 commonjs cjs node10 moduleResolution modules regression

🕗 Version & Regression Information

⏯ Playground Link

SBoudrias/Inquirer.js#1554

💻 Code

My tsconfig.cjs.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "lib": ["es2023"],
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node10",
    "outDir": "dist/cjs",
    "declarationDir": "dist/cjs/types"
  }
}

🙁 Actual behavior

The files outputted in dist/cjs are now using esm module syntax instead fo cjs (import ... from).

🙂 Expected behavior

As of version 5.5.4, the files outputted in dist/cjs were cjs (require(...)).

Additional information about the issue

No response

@Andarist
Copy link
Contributor

bisects to #59479

@Andarist
Copy link
Contributor

So it seems that before this PR it would ignore the fact that your files are authored using .mts and it would allow you to compile that to a commonjs module. With the new version the extension is always taken into consideration, even with "moduleResolution": "node10".

We can trace back this work to #57896 and #58825 . They mention that from now on extensions should be considered in more module modes but they are not as explicit when it comes to what does it mean for moduleResolution modes.

This is a one-line change to fix your issue but the changed code is also almost explicit when it comes to applying the new logic for extensions regardless of moduleResolution... so I think it's best to ping @andrewbranch and defer to his opinion about this.

Minimal repro case:

// @moduleResolution: node10
// @module: commonjs

// @filename: index.mts
export const foo = ''

@andrewbranch
Copy link
Member

Yes, this is working as intended. Compiling .mts files to CommonJS-containing .mjs files was not something we ever intended to support—the fact that it ever worked was a bug / unintentional side effect of other work.

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants