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

module: Preserve #29

Open
fregante opened this issue Aug 21, 2024 · 8 comments
Open

module: Preserve #29

fregante opened this issue Aug 21, 2024 · 8 comments

Comments

@fregante
Copy link
Contributor

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-4.html#support-for-require-calls-in---moduleresolution-bundler-and---module-preserve

I think this is the right config to finally get TS out of the way

{
    "compilerOptions": {
        "module": "preserve",
        // ^ also implies:
        // "moduleResolution": "bundler",
        // "esModuleInterop": true,
        // "resolveJsonModule": true,
        // ...
    }
}

More info in microsoft/TypeScript#56785

@sindresorhus
Copy link
Owner

What's the benefit for ESM-only projects? Not sure I see the value in it.

@fregante
Copy link
Contributor Author

I think the benefit is to stop fighting TypeScript with imports: just let the user use what they write. Specific rules/preferences can be enforced via eslint.

Or at least that’s the promise

@sindresorhus
Copy link
Owner

There is really no fighting if you are pure ESM. And I don't really see the point in allowing require here and then use a linter to disallow it, when it can just be disallowed here instead.

@fregante
Copy link
Contributor Author

fregante commented Aug 21, 2024

There is really no fighting if you are pure ESM

I reached this point because this config blocks import attributes AKA “pure ESM”, so the fight still exists. Then node wants .ts imports and TS wants .js imports. The fight continues.

If preserve keeps its promise to just allow modules as written, I think it’s advantageous.

@fregante
Copy link
Contributor Author

fregante commented Aug 21, 2024

This is what I see with @sindresorhus/tsconfig 6, without changes: ESM is not allowed, require is:

Screenshot 13

@sindresorhus
Copy link
Owner

If preserve keeps its promise to just allow modules as written, I think it’s advantageous.

I suggest trying it out in practice first on some popular projects to see its effects. I'm already lukewarm to it, but I'm definitely not adding it here until it's proven to work.

@sindresorhus
Copy link
Owner

This is what I see with @sindresorhus/tsconfig 6, without changes: ESM is not allowed, require is:

That's just the fact of using TS in general. Every JS feature has to be supported by TS before you can use it there. I thought TS already supported import attributes: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html

@fregante
Copy link
Contributor Author

I thought TS already supported import attributes

They do, but you have to use a specific config (and this config particularly blocks resolveJsonModule because Node <18.20 doesn't support it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants