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

Missing "vite-manifest.json" file on build #10268

Closed
stephenlrandall opened this issue Jun 27, 2023 · 23 comments · Fixed by #10782
Closed

Missing "vite-manifest.json" file on build #10268

stephenlrandall opened this issue Jun 27, 2023 · 23 comments · Fixed by #10782

Comments

@stephenlrandall
Copy link
Contributor

Describe the bug

Building a SvelteKit application on one of my GitLab runners breaks with:

[vite-plugin-svelte-compile] ENOENT: no such file or directory, open '.../.svelte-kit/output/client/vite-manifest.json'

On my local machine, the build is fine. I was curious about the vite-manifest.json file, and it looks like it's actually generated:

✓ 1268 modules transformed.
.svelte-kit/output/client/_app/version.json                           0.03 kB │ gzip:   0.05 kB
.svelte-kit/output/client/vite-manifest.json                         38.84 kB │ gzip:   2.79 kB
...

But if I go inspect that folder after the build is complete, that file isn't present. Does it get deleted at some point? Is there any chance of a race condition happening?

The exact line that spawns the error is:

const client_manifest = JSON.parse(read(`${out}/client/${vite_config.build.manifest}`));

Reproduction

I don't know how to reproduce this, it's only happening on a system I don't control.

Logs

No response

System Info

System doesn't have external internet access, but it's using:

@sveltejs/adapter-static: 2.0.2
@sveltejs/kit: 1.15.7
svelte: 3.58.0
vite: 4.3.2

Severity

blocking all usage of SvelteKit

Additional Information

Apologies for the lack of a good reproduction, more so just trying to understand where to continue debugging the issue.

@gtm-nayan
Copy link
Contributor

Is the ... an absolute path replaced or was it actually there in the message?

@stephenlrandall
Copy link
Contributor Author

Is the ... an absolute path replaced or was it actually there in the message?

An absolute path replaced for privacy, apologies if that was confusing.

@gtm-nayan
Copy link
Contributor

Check if the issue occurs in a new blank project deployed on GitLab.

@stephenlrandall
Copy link
Contributor Author

Check if the issue occurs in a new blank project deployed on GitLab.

Sorry for the long delay -- yes, the problem also occurs with the default starter SvelteKit app.

Again the Vite build log is saying that a vite-manifest.json file is being created, but it's not being found. Locally, where the build does work, I'm also not seeing a vite-manifest.json file in my build output. Do you know what's going on with that file?

@gtm-nayan
Copy link
Contributor

I'm also not seeing a vite-manifest.json file in my build output. Do you know what's going on with that file?

It's removed after the build is done so that's expected at least but I don't see why it'd behave differently on GitLab.

fs.unlinkSync(`${out}/client/${vite_config.build.manifest}`);

The plugin name from the error, vite-plugin-svelte-compile is odd, the name's not used in either SvelteKit or vite-plugin-svelte, are you using any others?

@stephenlrandall
Copy link
Contributor Author

stephenlrandall commented Jul 6, 2023

The plugin name from the error, vite-plugin-svelte-compile is odd, the name's not used in either SvelteKit or vite-plugin-svelte, are you using any others?

Isn't this it?

/** @type {import('vite').Plugin} */
const plugin_compile = {
name: 'vite-plugin-sveltekit-compile',

It's the same error on the demo project, with nothing extra added.


I'm wondering if there's a race condition happening, because in the logs I do see the "done ..." lines from the build output at the same time the error appears. So it seems as though the build completes, but then that last plugin is running too late to still have the vite-manifest.json file around?

@stephenlrandall
Copy link
Contributor Author

@gtm-nayan Is there any more information I can give to help with this? It looks like the “awaiting submitter” tag is still applied.

@gtm-nayan
Copy link
Contributor

Ah sorry, I forgot to send the comment I had typed out.

The plugin name is missing kit in the error message in your original post, was that missed out when pasting or does the actual error report the plugin as vite-plugin-svelte-compile? There shouldn't be a race condition since the function that deletes the files is only called after everything has completed.

@stephenlrandall
Copy link
Contributor Author

The plugin name is missing kit in the error message in your original post, was that missed out when pasting or does the actual error report the plugin as vite-plugin-svelte-compile?

Ah, sorry, I did copy it over incorrectly. The error does reference vite-plugin-sveltekit-compile.

The relevant part of the build log I see is:

> Using @sveltejs/adapter-static
    Wrote site to "build"
    ✓ done
✓ built in 8.44s
[vite-plugin-sveltekit-compile] ENOENT: no such file or directory, open '.../.svelte-kit/output/client/vite-manifest.json'
✓ built in 12.77s
error during build:
Error: ENOENT: no such file or directory, open '.../.svelte-kit/output/client/vite-manifest.json'
    at ...

The full path of the error uses a mix of / and \, which I assume is okay:

ENOENT: no such file or directory, open 'C:\gitlab-runner-XXX\builds\YYY\0\ZZZ\repo-name\.svelte-kit/output/client/vite-manifest.json'

The double ✓ built in ... lines confuse me a bit -- is there any reason that would happen? Locally I don't see that issue at all, and my GitLab CI file is just running the usual npm run build.

@gtm-nayan
Copy link
Contributor

The double built in lines are for the two vite client and server builds I think which should be fine. Although the logs seem out of order, I'm confused why the adapter log would show up above the others when it should be at the end.

Could you please share the blank project that reproduced the issue on gitlab with the CI scripts configured?

@stephenlrandall
Copy link
Contributor Author

They both seem to be associated with the server build, curiously:

.svelte-kit/output/client/_app/version.json                             ...
.svelte-kit/output/client/vite-manifest.json                            ...
...
✓ built in 2.28s
.svelte-kit/output/server/vite-manifest.json                            ...
...
.svelte-kit/output/server/index.js                                      ...
Run npm run preview to preview your production build locally.
> Using @sveltejs/adapter-static
    Wrote site to "build"
    ✓ done
✓ built in 8.44s
[vite-plugin-sveltekit-compile] ENOENT: no such file or directory, open '.../.svelte-kit/output/client/vite-manifest.json'
✓ built in 12.77s
error during build:
Error: ENOENT: no such file or directory, open '.../.svelte-kit/output/client/vite-manifest.json'
    at ...

It almost seems as though something in the server build is trying to happen twice?


The blank project used is the default Sverdle app with nothing extra enabled. The CI is a little funky because the system doesn't have internet access, so it's copying a pre-populated set of node modules over:

image: node:latest

.deploy-template:
  stage: deploy
  script:
    - "if (-not (Test-Path: P:\\)) { net use P: \\\\drive\\name\folder }"
    - $env:NODE_HOME = "P:\\software\\<path>\\node\\node-19.6.1"
    - $env:PATH = "$env:NODE_HOME;$env:PATH"
    - cp "P:\\software\\<path>\\node_modules_archive.zip" .
    - Expand-Archive -Path "node_modules_archive.zip"
    - mv node_modules_archive/node_modules node_modules
    - npm run build
    - mv build public
  artifacts:
    paths:
      - public
    when: always
    tags:
      - executor:powershell

pages:
    extends: [.deploy-template]
    only:
      - main

(Copied over manually, so may have typos.)

@stephenlrandall
Copy link
Contributor Author

stephenlrandall commented Jul 11, 2023

Somewhat unsurprisingly, if I comment out the following lines:

// avoid making the manifest available to users
fs.unlinkSync(`${out}/client/${vite_config.build.manifest}`);
fs.unlinkSync(`${out}/server/${vite_config.build.manifest}`);

the build goes through just fine.

But, looking at the logs, the server build is run twice...

@fbele
Copy link

fbele commented Jul 14, 2023

I have the same issue here. It's happening with Ionic Extension for VS Code when you want to run application in Android Emulator in combination with Capacitor. And it happens only there and only if the application was already built once using the extension, the first run works just fine for me. If I just close VS Code and run the application is going to be built just fine. Also if I run application via npx cap run android it runs just fine.

One workaround for now that I suggest is that you use npx cap run android whenever run is not working using Ionic Extension. When the app is running you can still attach the debugger using Ionic extension if you need it.

@stephenlrandall
Copy link
Contributor Author

That’s interesting, but my use case is entirely different since I’m seeing the issue in a GitLab runner, not within the VS Code terminal.

@gtm-nayan Do you have any idea why the server build might run twice under any circumstances?

@Miolus
Copy link

Miolus commented Jul 28, 2023

Same issue here on VSCode with internet access and node adapter.

@stephenlrandall
Copy link
Contributor Author

Same issue here on VSCode with internet access and node adapter.

If you rewind the kit/Vite packages a few versions, how far back do you have to go before the deployment works?

@kiddailey
Copy link

kiddailey commented Aug 3, 2023

Just adding my comment as I have this issue as well. (Windows 11, Svelte 3.59.2, Kit 1.22.3, Adapter-Static 2.0.3, Vite 4.4.7, currently using Node 16.18.1)

I have a very simple, default setup to build a non-SPA static site. The build process does successfully complete and then the error pops up just as described in the original issue above. For what it's worth, I don't see the issue when running the site with "vite dev"

I don't remember this being an issue when I first setup Svelte for my project, originally with Svelte 3.54.0, Kit 1.0.13, Adapter-Static 1.0.1 and Vite 4.0.0.

Edit: Did testing and figured out where the issue begin. See next post...

@kiddailey
Copy link

kiddailey commented Aug 3, 2023

Okay, summary of results from testing:

  • The issue appears to have been introduced with SvelteKit v1.3.1
  • The issue does NOT occur with SvelteKit v1.3.0 regardless of Svelte or Vite versions.

If you want to test it out yourself, here's a snippet from package.json for an environment that works correctly (no error):

"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/adapter-static": "^1.0.6",
"@sveltejs/kit": "^1.3.0",
"svelte": "^3.59.2",
"svelte-preprocess": "^5.0.4",
"vite": "^4.4.7"

And one that does NOT work, outputting the error originally reported:

"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/adapter-static": "^1.0.6",
"@sveltejs/kit": "^1.3.1",
"svelte": "^3.59.2",
"svelte-preprocess": "^5.0.4",
"vite": "^4.4.7"

You'll see that the only difference is SvelteKit. Note that adapter-static is capped at v1.0.6 for SvelteKit v1.3.0. Hope this helps solve the mystery.

Edit: Narrowed-in on exact minor versions from further testing

I also noticed that one of the pull requests from 1.3.1 ( #8636 ) mentioned in the 1.3.1 release notes contains changes directly related to where the manifest file is loaded from. Might be a good starting point. Hope that helps.

@emaktech
Copy link

emaktech commented Aug 8, 2023

Thanks @kiddailey

Can confirm when running npm install @sveltejs/kit@1.3.0 and then trying npm run build again it works fine!

@stephenlrandall
Copy link
Contributor Author

Same for me, locking kit at 1.3.0 and adapter-static at 1.0.6 fixes the issue.

@Rich-Harris Sorry for the ping, but as the author of #8636 do you have any ideas about why it might be causing the server build to run twice under certain circumstances?

@stephenlrandall
Copy link
Contributor Author

@benmccann Since you reviewed #8636, do you have any ideas about why it might cause the server build to run twice? I'm seeing the issue on (one of) my GitLab runners, and it seems like other people are experiencing the same problem. The issue can be worked around by locking to SvelteKit 1.3.0 and adapter-static 1.0.6, but this is obviously non-ideal.

@midhunhk
Copy link

One observation I made is running vite build from the command line works, but npm run build, which essentially says "build": "vite build" is failing. No clue why they should be behaving differently.

@opack
Copy link

opack commented Sep 25, 2023

I do have the same issue when trying to run the Playwright tests in VSCode. It fails with this error when executing from the "Playwright Test for VSCode" extension, but works like a charm when running npm run test:integration in the terminal.

I also confirm that as @stephenlrandall said above, commenting those two lines in node_modules\@sveltejs\kit\src\exports\vite\index.js makes the problem disappear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants