-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Ensure .js
extensions are present with Typescript 5
#205
Comments
For anyone running into the issue for the meantime, I was able to get .js extensions added by installing ts-patch and using typescript-transform-extensions. Obviously not the ideal solution, but it will work for now. |
There's a lot to unpack in that TS issue, but I kind of agree with their final decision. There's also a summary of that thread from microsoft/TypeScript#16577 (comment). I'm not sure what we should do for Can you also elaborate how adding |
The reason Since ESM spec requires import extensions I think this could be another QoL thing |
I don't understand. If I import src/libs in src/routes from the same project I don't experience any errors. (Accidental close) |
Here's a repo demonstrating the problem: https://github.com/mattjennings/svelte-kit-package-extensions-bug |
Ok I understand - you're stuck in an either-or situation. Either make it work for webpack, or work internally, but not both. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
People authoring packages can solve this now by using node 16 / nodenext. They need to change the following settings in their tsconfig.json:
Support for this will land in the next release of Svelte language-tools, I'll update this message once it's released. I don't think we should change this setting for all users to this though, because then everyone is required to adhere to the new node resolution rules (which means explicit file endings for relative imports), not just package authors. |
Importing |
Discovered through comment in #2040 This is necessary so people can use this new resolution mode and still get proper typings for things like $app/stores This isn't all that's needed though: - Vite 3 is needed so we get their exports map which makes vite/client resolve correctly - Svelte bump needed to properly expose CompileOptions. It's imported from a path which isn't accessible when adhering to export maps
) Discovered through comment in #2040 This is necessary so people can use this new resolution mode and still get proper typings for things like $app/stores This isn't all that's needed though: - Vite 3 is needed so we get their exports map which makes vite/client resolve correctly - Svelte bump needed to properly expose CompileOptions. It's imported from a path which isn't accessible when adhering to export maps Co-authored-by: Simon <simon.holthausen@accso.de>
Could you create a new issue for this with a reproduction? |
I'm not sure that |
TypeScript will (in 5.0? don't know) ship more fine grained module resolution flags, which hopefully solve this issue. |
.js
extensions are present with Typescript 5
See also sveltejs/kit#12163 |
Describe the problem
This is a Typescript problem (see this, and this), but package is affected by this because it produces ESM javascript.
Say your
src/lib
folder has two files in it:index.ts
andstore.ts
. Yourindex.ts
looks like this:When you compile with
svelte-kit package
, the result is this:Because there's no .js file extension, this is will likely fail in ESM. SvelteKit projects seem to handle this fine (I'm not sure why), but projects using webpack for example will fail with the following error:
Describe the proposed solution
Frustratingly, it seems Typescript's stance on this is to add .js to your file extensions in your .ts files. This works when compiling through
package
, but will not work if you want to consumesrc/lib
yourself within the kit project (i.e under/routes
, if you wanted to set up docs or something).The only way around this that I can think of is to add .js extensions in a post-compilation script. Similar to how tsc-esm does it. It's dumb that kit has to care about this, but I think it's going to be a common gotcha for many library authors otherwise.
Alternatives considered
Importance
would make my life easier
Additional Information
In that
tsc-esm
package, it uses a utility file from grubber to add the .js extensions. I wrote up a script and ran it against my package output:and it worked on everything except my index.js file, but I haven't looked much further into that.
The text was updated successfully, but these errors were encountered: