Skip to content

@sveltejs/kit 2.21.0 -> 2.21.1 cause error no such file or directory, open 'src/routes/+layout.js' #13804

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

Closed
xmlking opened this issue May 18, 2025 · 11 comments

Comments

@xmlking
Copy link

xmlking commented May 18, 2025

Describe the bug

when I build my application with @sveltejs/kit 2.21.1 getting this error.
no error building with 2.21.0

onsole:build: node:internal/event_target:1101
console:build:   process.nextTick(() => { throw err; });
console:build:                            ^
console:build: Error: ENOENT: no such file or directory, open 'src/routes/+layout.js'
console:build:     at Object.readFileSync (node:fs:443:20)
console:build:     at read (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/utils/filesystem.js:199:12)
console:build:     at get_page_options (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/exports/vite/static_analysis/index.js:217:19)
console:build:     at async build_server_nodes (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/exports/vite/build/build_server.js:117:25)
console:build:     at async analyse (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:69:2)
console:build:     at async MessagePort.<anonymous> (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/utils/fork.js:23:16) {
console:build:   errno: -2,
console:build:   code: 'ENOENT',
console:build:   syscall: 'open',
console:build:   path: 'src/routes/+layout.js'
console:build: }
console:build: 
console:build: Node.js v23.11.0
console:build:  ELIFECYCLE  Command failed with exit code 1.
console:build: ERROR: command finished with error: command (/xxx/Work/web/spectacular/apps/console) /opt/homebrew/bin/pnpm run build exited (1)
console#build: command (/xxx/Work/web/spectacular/apps/console) /opt/homebrew/bin/pnpm run build exited (1)

Reproduction

https://github.com/xmlking/spectacular/tree/main/apps/console

Logs

onsole:build: node:internal/event_target:1101
console:build:   process.nextTick(() => { throw err; });
console:build:                            ^
console:build: Error: ENOENT: no such file or directory, open 'src/routes/+layout.js'
console:build:     at Object.readFileSync (node:fs:443:20)
console:build:     at read (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/utils/filesystem.js:199:12)
console:build:     at get_page_options (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/exports/vite/static_analysis/index.js:217:19)
console:build:     at async build_server_nodes (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/exports/vite/build/build_server.js:117:25)
console:build:     at async analyse (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:69:2)
console:build:     at async MessagePort.<anonymous> (file:///xxx/Work/web/spectacular/node_modules/.pnpm/@sveltejs+kit@2.21.1_@sveltejs+vite-plugin-svelte@3.1.2_svelte@4.2.19_vite@5.4.18_@type_2e4ec76b3db225e8be9cd6d2fc90027f/node_modules/@sveltejs/kit/src/utils/fork.js:23:16) {
console:build:   errno: -2,
console:build:   code: 'ENOENT',
console:build:   syscall: 'open',
console:build:   path: 'src/routes/+layout.js'
console:build: }
console:build: 
console:build: Node.js v23.11.0
console:build:  ELIFECYCLE  Command failed with exit code 1.
console:build: ERROR: command finished with error: command (/xxx/Work/web/spectacular/apps/console) /opt/homebrew/bin/pnpm run build exited (1)
console#build: command (/xxx/Work/web/spectacular/apps/console) /opt/homebrew/bin/pnpm run build exited (1)

System Info

System:
    OS: macOS 15.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 20.89 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.11.0 - /opt/homebrew/bin/node
    npm: 10.9.2 - /opt/homebrew/bin/npm
    pnpm: 10.10.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 136.0.7103.114
    Chrome Canary: 138.0.7186.0
    Edge: 135.0.3179.54
    Safari: 18.5

Severity

annoyance

Additional Information

No response

@eltigerchino
Copy link
Member

Please provide a minimal reproduction, not your entire project.

@knd775
Copy link

knd775 commented May 23, 2025

I've tried for days to create a minimal repro, but haven't been successful. There's definitely an issue in 2.21.1, but isolating the cause has proven quite difficult.

@artemudovyk
Copy link

artemudovyk commented May 23, 2025

For some reason the build requires for the +layout.ts(js)/+page.ts(js) to exist, even if they are empty. But it does it for every +layout.svelte or +page.svelte that does not have its .ts(js) pair, e.g. when src/routes/+layout.ts is created, the error then goes to the next route (src/routes/foo/+page.ts) and so on.

Downgraded to 2.21.0 and the problem did not occur.

xmlking added a commit to xmlking/spectacular that referenced this issue May 24, 2025
@xmlking
Copy link
Author

xmlking commented May 24, 2025

to reproduce.
switch @sveltejs/kit version from 2.21.0 to 2.21.1 in pnpm-workspace.yaml and try

git clone https://github.com/xmlking/spectacular.git
pnpm i
turbo run console#build

@eltigerchino
Copy link
Member

eltigerchino commented May 26, 2025

to reproduce. switch @sveltejs/kit version from 2.21.0 to 2.21.1 in pnpm-workspace.yaml and try

git clone https://github.com/xmlking/spectacular.git
pnpm i
turbo run console#build

This is not a minimal reproduction. You'll need to make a copy of your project and remove all unrelated files that do not play a part in producing the bug.

@eltigerchino
Copy link
Member

@artemudovyk are you able to share a reproduction? I've tried to reproduce this by creating different combinations of pages and layouts but I can't get the build to fail

@artemudovyk
Copy link

artemudovyk commented May 29, 2025

@eltigerchino sure. Sorry couldn't do it alongside my first comment in the thread in the first place.

Reproduction:
https://github.com/artemudovyk/sveltekit-2-21-1-build-fail-repro

With houdini and houdini-svelte removed, the app builds successfully. Created a different branch to showcase that:
https://github.com/artemudovyk/sveltekit-2-21-1-build-fail-repro/tree/houdini-removed

The OP's repo has houdini in the dependencies as well.

Nothing about houdini in the error stack trace though.

@SeppahBaws
Copy link

Heya all

So this seems to be a problem with Houdini itself, and some of the inner workings we're having to do to make our magic work.

We need to mock a +page.js (or +layout.js) file through vite, which contains an auto-generated universal load to fetch the user's graphql query defined in that route. This works great with vite, but to make this work with SvelteKit we had to monkey patch some of the filesystem functions like readFileSync to trick SvelteKit into believing this file exists in the user's source tree.

The changes introduced with #13790 moved the build_server_nodes function around. It internally will try to load the file with fs.readFileSync through this call stack: build_server_nodes() -> get_page_options() -> read().
For some reason our readFileSync patch isn't getting called at this point, and it will use the normal readFileSync implementation in node, which will fail because that +page.js file doesn't exist in the user's source tree.

We haven't found a way around this issue yet, but the most ergonomic way would be if we had a way to easily tell SvelteKit that we're providing an auto-generated implementation for universal load functions on some specific routes. Alec already had an idea for this a couple of years ago: #6708

cc: @AlecAivazis

@eltigerchino
Copy link
Member

We haven't found a way around this issue yet, but the most ergonomic way would be if we had a way to easily tell SvelteKit that we're providing an auto-generated implementation for universal load functions on some specific routes. Alec already had an idea for this a couple of years ago: #6708

Related to #8896

@AlecAivazis
Copy link

Alright we have a path forward albeit with a potentially unfortunate side effect - we will likely have to give up our +page.gql API. To be fair, it was built on shaky grounds that lasted a lot longer than it should. Ultimately this will force us to line up a lot closer with svelte's new direction for async loading. Forcing functions like this are always slightly uncomfortable (in a good way).

i'm now working on houdini-svelte@3.0 which will strip away a lot of the black magic we were relying on in favor of a much simpler model and will be compatible with the latest and greatest kit is bringing to the table. Once it's ready, this version of houdini-svelte will be available under the @next tag until houdini@2.0 is ready. Until then Houdini users will need to limit their applications to only use versions at or below 2.21.0

i think this ticket is good to close and anyone who is running into this while using Houdini is encouraged to open up an issue over on our repo for us to take a look.

@eltigerchino
Copy link
Member

Alright we have a path forward albeit with a potentially unfortunate side effect - we will likely have to give up our +page.gql API. To be fair, it was built on shaky grounds that lasted a lot longer than it should. Ultimately this will force us to line up a lot closer with svelte's new direction for async loading. Forcing functions like this are always slightly uncomfortable (in a good way).

i'm now working on houdini-svelte@3.0 which will strip away a lot of the black magic we were relying on in favor of a much simpler model and will be compatible with the latest and greatest kit is bringing to the table. Once it's ready, this version of houdini-svelte will be available under the @next tag until houdini@2.0 is ready. Until then Houdini users will need to limit their applications to only use versions at or below 2.21.0

i think this ticket is good to close and anyone who is running into this while using Houdini is encouraged to open up an issue over on our repo for us to take a look.

Thank you for looking into this! Let us know if there's anything more we can do from our side.

@eltigerchino eltigerchino closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2025
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

6 participants