-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Example apps should include file extensions in import statements #204
Comments
This is an unintended consequence of the fact that those files are generated from typescript source, but touché - we should definitely fix this |
While I agree this was a design mistake in node module resolution, I don't think we should change it right now.
|
I don't agree with this — people might be surprised, because they're used to doing things wrong, but no-one will be confused by it since it reduces ambiguity.
not sure I follow? I'm only suggesting we'd add the
The VSCode default is to match existing imports — if you have an existing |
https://www.typescriptlang.org/docs/handbook/esm-node.html recommends including the |
The TypeScript files aren't intended for running as ESM in Node though — they're consumed via a bundler rather than transpiled 1:1. It would 'work' for the TypeScript case but I think it's just too weird to have modules explicitly referencing |
Same is true for the JavaScript files though, it's all processed by Vite |
Of course, but the arguments in favour of using file extensions still hold |
FWIW TypeScript is introducing new moduleResolution options for 5.0, microsoft/TypeScript#50152, which would allow using .ts extensions |
In which case we should definitely switch to using file extensions when 5.0 lands. In the meantime the question is whether 4.x's behaviour is reason enough to keep doing the wrong thing for JavaScript projects in the name of consistency, to which I would argue the answer is definitely 'no' |
Hi, I just wanted to bump this discussion now that TS 5.0 is well and truly out. "moduleResolution": "bundler" allows optional ".js" extensions in imports, as well as optional ".ts" extensions in imports if |
Need to set allowImportingTsExtensions to import with .ts extension. See sveltejs/cli#204
Describe the problem
Per @Rich-Harris in nodejs/node#46074 (comment):
I ran
npm create svelte@latest
today and chose “SvelteKit demo app,” “JavaScript with JSDoc comments” and looked around at the files, and many had references to extensionless files. For example,src/routes/sverdle/+page.server.js
hasimport { Game } from './game';
(instead of./game.js
) andsrc/routes/sverdle/game.js
hasimport { words, allowed } from './words.server';
(instead of./words.server.js
).Describe the proposed solution
Let’s ensure that all the example
import
statements that refer to individual files (not library exports) include extensions, even for JavaScript files.Alternatives considered
No response
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: