kit: Imports broken with library updated to svelte-package v2
Describe the bug
I updated a lib to use svelte-package v2.
Previously I was using the lib like this:
<script lang="ts">
import { Button } from "kit-issue-9114";
</script>
<Button>Example</Button>
After updating I get an error from TS that the module does not exist. I found that if I add the output directory to the import, then it works:
Example:
<script lang="ts">
import { Button } from "kit-issue-9114/package";
</script>
<Button>Example</Button>
I’m not sure where the issue is here, I used the migration script and have gone through this doc.
Reproduction
https://github.com/seanlail/kit-issue-9114
Logs
Cannot find module 'kit-issue-9114' or its corresponding type declarations.ts
System Info
System:
OS: macOS 13.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 3.45 GB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
Browsers:
Chrome: 110.0.5481.100
Firefox: 99.0.1
Safari: 16.2
npmPackages:
@sveltejs/adapter-static: 2.0.1 => 2.0.1
@sveltejs/kit: 1.7.2 => 1.7.2
@sveltejs/package: 2.0.1 => 2.0.1
svelte: 3.55.1 => 3.55.1
vite: 4.1.2 => 4.1.2
Severity
serious, but I can work around it
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 25 (15 by maintainers)
Commits related to this issue
- (feat) copy package.json functionality, update migration script closes #9114 — committed to sveltejs/kit by dummdidumm a year ago
- fix: use typesVersions to wire up deep imports and explain that stuff in the docs closes #9114 — committed to sveltejs/kit by dummdidumm a year ago
- fix: use typesVersions to wire up deep imports (#9133) and explain that stuff in the docs closes #9114 — committed to sveltejs/kit by dummdidumm a year ago
FYI I found a better solution to this which keeps us from introducing a fragile copy function: (ab)using the
typesVersions
feature from TypeScript to replicate the export path mappings. It’s explained in the linked PR’s docs which are hopefully up on the main Kit site soon. TheButton.svelte
example in this issue would be written as follows:svelte-migrate
will be updated to migrate this automatically, so it’s probably easiest to run the migration script again on your libraries to get thetypesVersions
addition to yourpackage.json
, copy it out, revert the rest, copy it back in.Yes:
package.json
intodist
folder (with adjusted export paths etc, so that the/dist
part is removed)cd dist
npm publish
(part 1 could be automated - the copy thing, not sure about the
/dist
adjustment thing. Given that it’s not uncommon we should probably have an option for that insvelte-package
) (yes this sounds like@sveltejs/package
version 1 but it’s not the same)