Skip to content
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

static-adapter and vite build --watch crashes if triggered while building. #10809

Open
RonniSkansing opened this issue Sep 29, 2023 · 11 comments

Comments

@RonniSkansing
Copy link

Describe the bug

vite build --watch crashes the processes due a unhanded error if I save while a build is running when using static-adapter.

Reproduction

https://github.com/RonniSkansing/svelte-vite-builld-watch-bug

To reproduce, clone the repo, run npm run build-watch and save twice in template file or js file.

The expected behavior is rebuild twice, the result is a crash.

Logs

➜  my-app  npm run build-watch

> [email protected] build-watch
> vite build --watch


vite v4.4.9 building SSR bundle for production...

watching for file changes...

build started...
✓ 72 modules transformed.

vite v4.4.9 building for production...
✓ 61 modules transformed.
.svelte-kit/output/client/_app/version.json                              0.03 kB │ gzip: 0.05 kB
.svelte-kit/output/client/vite-manifest.json                             2.12 kB │ gzip: 0.40 kB
.svelte-kit/output/client/_app/immutable/nodes/0.18524db0.js             0.60 kB │ gzip: 0.38 kB
.svelte-kit/output/client/_app/immutable/nodes/2.e362da2a.js             0.69 kB │ gzip: 0.44 kB
.svelte-kit/output/client/_app/immutable/nodes/1.4c0ce09b.js             1.03 kB │ gzip: 0.59 kB
.svelte-kit/output/client/_app/immutable/chunks/scheduler.e108d1fd.js    2.16 kB │ gzip: 1.02 kB
.svelte-kit/output/client/_app/immutable/chunks/singletons.94c50d8c.js   2.85 kB │ gzip: 1.46 kB
.svelte-kit/output/client/_app/immutable/chunks/index.a21d6cee.js        5.44 kB │ gzip: 2.31 kB
.svelte-kit/output/client/_app/immutable/entry/app.73759bd2.js           5.82 kB │ gzip: 2.30 kB
.svelte-kit/output/client/_app/immutable/entry/start.bd04ac13.js        24.90 kB │ gzip: 9.81 kB
✓ built in 556ms
.svelte-kit/output/server/vite-manifest.json                   1.29 kB
.svelte-kit/output/server/internal.js                          0.19 kB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js   0.24 kB
.svelte-kit/output/server/entries/pages/_page.svelte.js        0.37 kB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js    0.89 kB
.svelte-kit/output/server/chunks/ssr.js                        3.35 kB
.svelte-kit/output/server/chunks/internal.js                   5.46 kB
.svelte-kit/output/server/index.js                            90.08 kB
built in 1510ms.

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-static
  Wrote site to "build"done

build started...
✓ 0 modules transformed.

vite v4.4.9 building for production...
✓ 61 modules transformed.
.svelte-kit/output/client/_app/version.json                              0.03 kB │ gzip: 0.05 kB
.svelte-kit/output/client/vite-manifest.json                             2.12 kB │ gzip: 0.40 kB
.svelte-kit/output/client/_app/immutable/nodes/0.18524db0.js             0.60 kB │ gzip: 0.38 kB
.svelte-kit/output/client/_app/immutable/nodes/2.e362da2a.js             0.69 kB │ gzip: 0.44 kB
.svelte-kit/output/client/_app/immutable/nodes/1.4c0ce09b.js             1.03 kB │ gzip: 0.59 kB
.svelte-kit/output/client/_app/immutable/chunks/scheduler.e108d1fd.js    2.16 kB │ gzip: 1.02 kB
.svelte-kit/output/client/_app/immutable/chunks/singletons.94c50d8c.js   2.85 kB │ gzip: 1.46 kB
.svelte-kit/output/client/_app/immutable/chunks/index.a21d6cee.js        5.44 kB │ gzip: 2.31 kB
.svelte-kit/output/client/_app/immutable/entry/app.73759bd2.js           5.82 kB │ gzip: 2.30 kB
.svelte-kit/output/client/_app/immutable/entry/start.bd04ac13.js        24.90 kB │ gzip: 9.81 kB
✓ built in 526ms
.svelte-kit/output/server/vite-manifest.json                   1.29 kB
.svelte-kit/output/server/internal.js                          0.19 kB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js   0.24 kB
.svelte-kit/output/server/entries/pages/_page.svelte.js        0.37 kB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js    0.89 kB
.svelte-kit/output/server/chunks/ssr.js                        3.35 kB
.svelte-kit/output/server/chunks/internal.js                   5.46 kB
.svelte-kit/output/server/index.js                            90.08 kB
built in 1050ms.

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-static

build started...
✓ 0 modules transformed.
rendering chunks (6)...
node:internal/event_target:1016
  process.nextTick(() => { throw err; });
                           ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/my-app/.svelte-kit/output/server/internal.js' imported from /my-app/node_modules/@sveltejs/kit/src/core/postbuild/fallback.js
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:324:11)
    at moduleResolve (node:internal/modules/esm/resolve:943:10)
    at defaultResolve (node:internal/modules/esm/resolve:1129:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ESMLoader.import (node:internal/modules/esm/loader:524:22)
    at importModuleDynamically (node:internal/modules/esm/translators:110:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:300:10)
    at [kOnMessage] (node:internal/worker:311:37)
    at MessagePort.<anonymous> (node:internal/worker:212:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:741:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28) {
  code: 'ERR_MODULE_NOT_FOUND'
}

System Info

System:
    OS: Linux 6.2 Ubuntu 23.04 
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/adapter-static: ^2.0.3 => 2.0.3 
    @sveltejs/kit: ^1.20.4 => 1.25.1 
    svelte: ^4.0.5 => 4.2.1 
    vite: ^4.4.2 => 4.4.9

Severity

annoyance

Additional Information

I am using vite build --watch so I can develop while another program is serving the static project.
Any work arounds would also be appreciated.

@RonniSkansing RonniSkansing changed the title static-adaper and vite build --watch crashes if triggered while building. static-adapter and vite build --watch crashes if triggered while building. Sep 29, 2023
@eltigerchino
Copy link
Member

eltigerchino commented Oct 4, 2023

The reproduction repository only has a README.md file. I can't reproduce the issue.

@RonniSkansing
Copy link
Author

Forgot to commit the files! Pushed to the repo.

@eltigerchino
Copy link
Member

Thanks! However, I can't reproduce the same issue. I'm getting a different error instead when saving twice.

Error: ENOENT: no such file or directory, unlink '/home/projects/github-uq4xbd/.svelte-kit/output/client/vite-manifest.json'
    at Object.unlinkSync (https://githubuq4xbd-rtoo.w-credentialless.staticblitz.com/blitz.5e765aa0.js:49:22024)
    at finalise (file:///home/projects/github-uq4xbd/node_modules/@sveltejs/kit/src/exports/vite/index.js:827:22)
    at Object.handler (file:///home/projects/github-uq4xbd/node_modules/@sveltejs/kit/src/exports/vite/index.js:854:21)
    at eval (file:///home/projects/github-uq4xbd/node_modules/rollup/dist/es/shared/node-entry.js:25569:40)
    at async PluginDriver.hookParallel (file:///home/projects/github-uq4xbd/node_modules/rollup/dist/es/shared/node-entry.js:25491:17)
    at async Object.close (file:///home/projects/github-uq4xbd/node_modules/rollup/dist/es/shared/node-entry.js:26751:13) {
  syscall: 'unlink',
  errno: -2,
  code: 'PLUGIN_ERROR',
  path: '/home/projects/github-uq4xbd/.svelte-kit/output/client/vite-manifest.json',
  pluginCode: 'ENOENT',
  plugin: 'vite-plugin-sveltekit-compile',
  hook: 'closeBundle'
}

The above should be fixed in the next release because of #10782 . In that PR, we no longer try to delete the vite-manifest file.

@RonniSkansing
Copy link
Author

Tried cloning the repo again and got the same error regarding .svelte-kit/output/server/internal.js however I previously also had the error with vite-manifest.json.

I think we should wait for the next release and see if it fixes this issue

@eltigerchino
Copy link
Member

I have a feeling it would still occur when it tries to read .svelte-kit/output/server/internal.js during the build. Something about the new build starting and deleting files while the previous build is still carrying on and trying to read files it wrote?

@RonniSkansing
Copy link
Author

It is definitely something racing. I tried to reproduce again and most of the time I get error vite-manifest.json and rarely internal.js

Perhaps patching with #10782 would make it easier to reproduce.

@eltigerchino
Copy link
Member

@RonniSkansing the patch is out in the latest release of Kit. Can you provide an update on the frequency of the errors?
https://github.com/sveltejs/kit/releases/tag/%40sveltejs%2Fkit%401.25.2

@RonniSkansing
Copy link
Author

RonniSkansing commented Oct 10, 2023

Thanks for updating me @s3812497

After updating and with a fresh clone of the bug repo, I constantly get the error

 Cannot find module 'svelte-vite-builld-watch-bug/.svelte-kit/output/server/internal.js' imported from svelte-vite-builld-watch-bug/node_modules/@sveltejs/kit/src/core/postbuild/fallback.js

However I have another repo, that is set up in the same way with a build --watch and it gives a different error.

'project/.svelte-kit/output/server/manifest-full.js' imported from /project/node_modules/@sveltejs/kit/src/core/postbuild/fallback.js

but I am not sure why they give different errors. I think it would be best to investigate the first mentioned error with https://github.com/RonniSkansing/svelte-vite-builld-watch-bug

I have updated the package.json and pushed, so hopefully it should be possible to reproduce now.

@eltigerchino
Copy link
Member

Thanks for the additional logs. That narrows down the error to kit/src/core/postbuild/fallback.js. Not generating a fallback page should solve the issue but we still need a more concrete solution to support vite build --watch such as ensuring the previous build has ended before starting a new one.

@RonniSkansing
Copy link
Author

Thanks for investigating, I can confirm that I do not get any crashes when not using a fallback page, so I will do that for now.

@RonniSkansing
Copy link
Author

RonniSkansing commented Nov 2, 2023

A temp work around is running the watch command in a loop. It is not optimal, but it makes it easier to develop until a fix is made.

Example:

while true; do \
  npm run build-watch; \ 
  echo "Process crashed! Restarting..."; \
done

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

2 participants