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

Error [RollupError]: Could not resolve "../dist/assets.json" from "renderer/_default.page.server.ts" after upgrade 0.4.161 #1501

Closed
nestle49 opened this issue Feb 19, 2024 · 18 comments
Labels

Comments

@nestle49
Copy link

nestle49 commented Feb 19, 2024

Description

I import manifest inside renderer/_default.page.server.ts:

const getManifest = import('../dist/assets.json').catch(() => ({ default: {} }))

After upgrade from 0.4.160 -> 0.4.161 (or higher) I discovered assets.json renamed client/_temp_manifest.json

After build error I looked at the changelog again https://github.com/vikejs/vike/blob/main/CHANGELOG.md, but didn't see this change or guid for migration

@nestle49
Copy link
Author

now assets.json exist, what's happens?

@DaniilIsupov
Copy link

I have same problem, but only if I install dependencies with production flag
npm i --production

@DaniilIsupov
Copy link

@brillout
Copy link
Member

Let me try to reproduce.

@brillout
Copy link
Member

I cannot reproduce, can one of you publish a reproduction?

@brillout
Copy link
Member

const getManifest = import('../dist/assets.json').catch(() => ({ default: {} }))

After upgrade from 0.4.160 -> 0.4.161 (or higher) I discovered assets.json renamed client/_temp_manifest.json

The assets JSON should still be emitted at dist/assets.json, if it's missing then it's a bug. (Vite say that it's generating dist/client/_temp_manifest.json and dist/server/_temp_manifesrt.json which is true but Vike merges & moves it to assets.json.)

@nestle49
Copy link
Author

const getManifest = import('../dist/assets.json').catch(() => ({ default: {} }))
After upgrade from 0.4.160 -> 0.4.161 (or higher) I discovered assets.json renamed client/_temp_manifest.json

The assets JSON should still be emitted at dist/assets.json, if it's missing then it's a bug. (Vite say that it's generating dist/client/_temp_manifest.json and dist/server/_temp_manifesrt.json which is true but Vike merges & moves it to assets.json.)

We will try to reproduce this error, but it is already clear that this does not always happen. That is, sometimes during a build temporary files are not deleted and the resulting file is not created

@brillout
Copy link
Member

I'll double check the source code for race conditions. I'll report back (ETA today or tomorrow).

@brillout
Copy link
Member

I don't see any potential race condition in here (the writeBundle() hooks are run in sequence), so I'm not sure how this can happen.

That is, sometimes during a build temporary files are not deleted and the resulting file is not created

Are there any thrown errors when this happens?

@DaniilIsupov
Copy link

I don't see any potential race condition in here (the writeBundle() hooks are run in sequence), so I'm not sure how this can happen.

That is, sometimes during a build temporary files are not deleted and the resulting file is not created

Are there any thrown errors when this happens?

x Build failed in 247ms
Error [RollupError]: Could not resolve "../dist/assets.json" from "renderer/_default.page.server.ts"
file: /renderer/_default.page.server.ts
    at getRollupEror (/node_modules/rollup/dist/es/shared/parseAst.js:375:41)
    at error (/node_modules/rollup/dist/es/shared/parseAst.js:372:42)
    at ModuleLoader.handleInvalidResolvedId (/node_modules/rollup/dist/es/shared/node-entry.js:18907:24)
    at ModuleLoader.resolveDynamicImport (/node_modules/rollup/dist/es/shared/node-entry.js:18967:58)
    at /node_modules/rollup/dist/es/shared/node-entry.js:18854:32 {
  code: 'UNRESOLVED_IMPORT',
  exporter: '../dist/assets.json',
  id: '/renderer/_default.page.server.ts',
  watchFiles: [
    '/renderer/_default.page.server.ts',
    '/constants/index.ts',
    '/renderer/app.ts',
    '/package.json',
    '/pages/router.ts',
    '/renderer/usePageContext.ts',
    '/layouts/default.vue'
  ]
}

@brillout
Copy link
Member

Alright, I see what's going on: Rollup is trying to analyze import('../dist/assets.json') which resolves to the assets.json file but it doesn't exist yet (it's generated after the build ends).

@DaniilIsupov You can try this workaround:

const manifestPath = '../dist/assets.json'
const manifest = await import(manifestPath)

@nestle49 I've further enforced the writeBundle() execution order df07c4d which is pre-released as [email protected], let me know if you still get the issue.

@nestle49
Copy link
Author

nestle49 commented Feb 20, 2024

@nestle49 I've further enforced the writeBundle() execution order df07c4d which is pre-released as [email protected], let me know if you still get the issue.

Yes, still relevant with [email protected] and workaround isn't working, same error traced:

x Build failed in 77ms
Error [RollupError]: Could not resolve "../dist/client/assets.json" from "renderer/_default.page.server.ts"
file: /Users/developer/PhpstormProjects/core/renderer/_default.page.server.ts
    at getRollupEror (file:///Users/developer/PhpstormProjects/core/node_modules/rollup/dist/es/shared/parseAst.js:375:41)
    at error (file:///Users/developer/PhpstormProjects/core/node_modules/rollup/dist/es/shared/parseAst.js:372:42)
    at ModuleLoader.handleInvalidResolvedId (file:///Users/developer/PhpstormProjects/core/node_modules/rollup/dist/es/shared/node-entry.js:18907:24)
    at ModuleLoader.resolveDynamicImport (file:///Users/developer/PhpstormProjects/core/node_modules/rollup/dist/es/shared/node-entry.js:18967:58)
    at file:///Users/developer/PhpstormProjects/core/node_modules/rollup/dist/es/shared/node-entry.js:18854:32 {
  code: 'UNRESOLVED_IMPORT',
  exporter: '../dist/client/assets.json',
  id: '/Users/developer/PhpstormProjects/core/renderer/_default.page.server.ts',

@brillout
Copy link
Member

How about this:

const manifestPath = '../dist/ass' + (1 + 1 < 3) && 'ets.json'
const manifest = await import(manifestPath)

Rollup shouldn't be able to analyze that.

@nestle49
Copy link
Author

nestle49 commented Feb 20, 2024

How about this:

const manifestPath = '../dist/ass' + (1 + 1 < 3) && 'ets.json'
const manifest = await import(manifestPath)

Rollup shouldn't be able to analyze that.

This will only work if you upgrade build.target, otherwise I get an error:

Error: [vite:esbuild-transpile] Transform failed with 1 error:
entries/renderer_default-page-server.mjs:5971:20: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
5969|  };
5970|  
5971|  const getManifest = await import("../dist/client/ass" + (1 + 1 < 3) + "ets.json").catch(() => ({ default: {} }));

But of course I wouldn’t want to use such code

@brillout
Copy link
Member

const rollupStaticAnalysisBuster = 1 + 1 < 10 ? '' : 'rollupStaticAnalysisBuster'
let manifest
export async funcion onRenderHtml() {
  manifest = manifest ?? await import("../dist/client/assets.json" + rollupStaticAnalysisBuster)
}

Also, I will make the assets manifest available over pageContext.

@DaniilIsupov
Copy link

@brillout as temporary solution, I did it like this

import { readFile } from 'fs/promises'

JSON.parse((await readFile(new URL('../../../dist/assets.json', import.meta.url))).toString())

I will wait to full fix this bug

@brillout
Copy link
Member

https://vike.dev/getGlobalContext released in 0.4.163.

@brillout
Copy link
Member

Btw. we're looking for sponsors, in case that's something your company would consider.

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

No branches or pull requests

3 participants