Can't build SvelteKit component libraries with `"moduleResolution": "NodeNext"`
See original GitHub issueDescribe the bug
When importing a TypeScript file with "moduleResolution": "NodeNext"
, an error occurs which prevents building SvelteKit apps.
These are the important files to reproduce the issue.
tsconfig.json
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
}
src/routes/index.svelte
<script lang="ts">
import { helloWorld } from '$lib/utils/hello_world.js';
const s = helloWorld();
</script>
<h1>{s}</h1>
src/lib/utils/hello_world.ts
export function helloWorld() {
return 'Hello world!';
}
Reproduction
Project:
https://github.com/NatoBoram/sk-import-dotjs-in-ts
Reproduction steps:
git clone git@github.com:NatoBoram/sk-import-dotjs-in-ts.git
cd sk-import-dotjs-in-ts
pnpm i
pnpm run build
Logs
> sk-import-dotjs-in-ts@0.0.1 build /home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts
> vite build
vite v2.9.13 building for production...
✓ 14 modules transformed.
.svelte-kit/output/client/_app/immutable/manifest.json 1.14 KiB
.svelte-kit/output/client/_app/immutable/layout.svelte-a1869e81.js 0.53 KiB / gzip: 0.35 KiB
.svelte-kit/output/client/_app/immutable/error.svelte-91b78de9.js 1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/_app/immutable/pages/index.svelte-320668b6.js 0.41 KiB / gzip: 0.30 KiB
.svelte-kit/output/client/_app/immutable/chunks/index-dd64db13.js 6.84 KiB / gzip: 2.79 KiB
.svelte-kit/output/client/_app/immutable/start-13c031ae.js 23.04 KiB / gzip: 8.73 KiB
vite v2.9.13 building SSR bundle for production...
✘ [ERROR] [plugin vite:dep-scan] ENOENT: no such file or directory, open '/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/src/lib/utils/hello_world.js'
node_modules/.pnpm/vite@2.9.13/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39676:43:
39676 │ let contents = fs__default.readFileSync(id, 'utf-8');
╵ ^
at Object.openSync (node:fs:599:3)
at Object.readFileSync (node:fs:467:35)
at /home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/vite@2.9.13/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39676:44
at callback (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:981:34)
at handleRequest (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:709:36)
at handleIncomingPacket (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:756:7)
at Socket.readFromStdout (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:632:7)
at Socket.emit (node:events:537:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
This error came from the "onLoad" callback registered here:
node_modules/.pnpm/vite@2.9.13/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39671:18:
39671 │ build.onLoad({ filter: JS_TYPES_RE }, ({ path: id }) => {
╵ ~~~~~~
at setup (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/vite@2.9.13/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39671:19)
at handlePlugins (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:843:23)
at Object.buildOrServe (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:1137:7)
at /home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:2085:17
at new Promise (<anonymous>)
at Object.build (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:2084:14)
at Object.build (/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/esbuild@0.14.48/node_modules/esbuild/lib/main.js:1931:51)
at /home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/node_modules/.pnpm/vite@2.9.13/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39389:54
at Array.map (<anonymous>)
The plugin "vite:dep-scan" was triggered by this import
script:/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/src/routes/index.svelte?id=0:2:28:
2 │ import { helloWorld } from '$lib/utils/hello_world.js';
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
[vite-plugin-svelte-kit] Build failed with 1 error:
node_modules/.pnpm/vite@2.9.13/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39676:43: ERROR: [plugin: vite:dep-scan] ENOENT: no such file or directory, open '/home/nato/Code/github.com/NatoBoram/sk-import-dotjs-in-ts/src/lib/utils/hello_world.js'
System Info
System:
OS: Linux 5.17 Pop!_OS 22.04 LTS
CPU: (4) x64 Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz
Memory: 12.10 GB / 23.42 GB
Container: Yes
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 18.4.0 - /usr/bin/node
Yarn: 1.22.18 - /usr/bin/yarn
npm: 8.12.1 - /usr/bin/npm
Browsers:
Chrome: 102.0.5005.115
Firefox: 102.0
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.53
@sveltejs/kit: next => 1.0.0-next.360
svelte: ^3.48.0 => 3.48.0
vite: ^2.9.13 => 2.9.13
Severity
blocking all usage of SvelteKit
Can be worked around by running tsc
(or tsc --watch
) in the workspace. Those files can be deleted with tsc --build --clean
.
Additional Information
The commands that fail are these:
pnpm run dev
pnpm run build
References
Issue Analytics
- State:
- Created a year ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Packaging • Docs • SvelteKit
You can use SvelteKit to build apps as well as component libraries, using the @sveltejs/package package ( npm create svelte has an option...
Read more >Connect your content to SvelteKit - Sanity.io
In this guide, you will add the necessary code to a SvelteKit starter to pull in your content from your Sanity Content Lake....
Read more >Recommended - SlideShare
Creating a project The easiest way to start building a SvelteKit app is ... Loading data Before a +page.svelte component (and its containing ......
Read more >Typescript: Cannot use import statement outside a module
If you want to emit CommonJS modules ( require ), set "module": ... Make sure your "main" field in package.json is pointing to...
Read more >Creating your first Svelte App with SvelteKit - Fjolt
Svelte is a frontend tool for creating web applications. In this tutorial we'll be looking at how to make your first Svelte application....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Perhaps you need to use custom scripts, though I’ve never used gitpkg (pretty cool though). But Vite should have a beta up soon. Though even so, Vite 3 is a major bump, so there may be breaking changes which are handled at https://github.com/sveltejs/kit/pull/5005 and https://github.com/sveltejs/vite-plugin-svelte/pull/359. I’d suggest sticking with the workaround for now though.
Dug into this. Looks like it’s a bug in the scanner where we didn’t implement the heuristic explained in the above comment when scanning. I’m making a PR to fix this upstream.