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

Open
xmlking opened this issue May 18, 2025 · 9 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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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/@[email protected]_@[email protected][email protected][email protected]_@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

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

5 participants