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

[Build] Prevent /server/assets creation in Vike V1 #2093

Open
rtritto opened this issue Jan 20, 2025 · 4 comments
Open

[Build] Prevent /server/assets creation in Vike V1 #2093

rtritto opened this issue Jan 20, 2025 · 4 comments
Labels
enhancement ✨ New feature or request

Comments

@rtritto
Copy link
Contributor

rtritto commented Jan 20, 2025

Description

With Vike design V0, /dist/server/assets files aren't bundled, while with V1 one they are bundled.

The bundle logic for Vike V1 was fixed in #2034 where /dist/server/assets/* files are created during the build and then removed.

The /dist/server/assets should not be bundled with Vike design V1 as V0 one.

Informations

Vike design V0

Run yarn build on vike-with-vercel#vike-design-v0

Build logs:

Running "yarn run build"
vite v6.0.8 building for production...
transforming...
9:58:50 AM [vike][Warning] Update to the new V1 design to get rid of Vite's warning: The glob option "as" has been deprecated in favour of "query". See https://vike.dev/migration/v1-design for how to migrate.
The glob option "as" has been deprecated in favour of "query". Please update `as: 'extractAssets'` to `query: '?extractAssets'`.
The glob option "as" has been deprecated in favour of "query". Please update `as: 'extractExportNames'` to `query: '?extractExportNames'`.
The glob option "as" has been deprecated in favour of "query". Please update `as: 'extractExportNames'` to `query: '?extractExportNames'`.
The glob option "as" has been deprecated in favour of "query". Please update `as: 'extractExportNames'` to `query: '?extractExportNames'`.
The glob option "as" has been deprecated in favour of "query". Please update `as: 'extractAssets'` to `query: '?extractAssets'`.
✓ 165 modules transformed.
rendering chunks...
computing gzip size...
dist/client/_temp_manifest.json                                                     3.39 kB │ gzip:  0.63 kB
dist/client/assets/static/logo.2_7Lo9tV.svg                                         5.79 kB │ gzip:  1.97 kB
dist/client/assets/static/renderer_PageLayout-5d219a08.Cjl9f7UM.css                 0.09 kB │ gzip:  0.10 kB
dist/client/assets/static/renderer_PageLayout-83e8fff7.B8X9vkNx.css                 0.38 kB │ gzip:  0.23 kB
dist/client/assets/entries/renderer_default.page.server.extractAssets.C6A_S5ZQ.js   0.07 kB │ gzip:  0.04 kB
dist/client/assets/entries/pages_about_index.page.DBUDFzb1.js                       0.33 kB │ gzip:  0.25 kB
dist/client/assets/entries/pages_index_index.page.B-lMgOj3.js                       0.67 kB │ gzip:  0.42 kB
dist/client/assets/entries/entry-server-routing.DROnmtSC.js                         2.77 kB │ gzip:  1.27 kB
dist/client/assets/entries/renderer_default.page.client.D33-c8Xt.js                 6.52 kB │ gzip:  3.04 kB
dist/client/assets/chunks/chunk-sE60adwL.js                                        32.28 kB │ gzip: 11.48 kB
dist/client/assets/entries/entry-client-routing.C-I6New4.js                        42.90 kB │ gzip: 14.13 kB
dist/client/assets/chunks/chunk-OxCnuAFn.js                                        57.63 kB │ gzip: 23.21 kB

vite v6.0.8 building SSR bundle for production...
transforming...
The glob option "as" has been deprecated in favour of "query". Please update `as: 'extractExportNames'` to `query: '?extractExportNames'`.
✓ 13 modules transformed.
rendering chunks...
dist/server/package.json                              0.02 kB
dist/server/_temp_manifest.json                       1.52 kB
dist/server/chunks/chunk-1tPrXgE0.js                  0.19 kB
dist/server/entries/pages_about_index-page.mjs        0.69 kB
dist/server/entries/pages_index_index-page.mjs        1.79 kB
dist/server/entry.mjs                                 2.43 kB
dist/server/entries/renderer_default-page-server.mjs  2.67 kB

Vike design V1

Run yarn build on vike-with-vercel#vike-design-v1

Build logs:

Running "yarn run build"
vite v6.0.8 building for production...
transforming...
✓ 99 modules transformed.
rendering chunks...
computing gzip size...
dist/client/_temp_manifest.json                                       2.17 kB │ gzip:  0.48 kB
dist/client/assets/static/logo.2_7Lo9tV.svg                           5.79 kB │ gzip:  1.97 kB
dist/client/assets/static/renderer_PageLayout-5d219a08.Cjl9f7UM.css   0.09 kB │ gzip:  0.10 kB
dist/client/assets/static/renderer_PageLayout-83e8fff7.B8X9vkNx.css   0.38 kB │ gzip:  0.23 kB
dist/client/assets/entries/pages_about.D7P7sZG6.js                    1.18 kB │ gzip:  0.53 kB
dist/client/assets/entries/pages_index.Dg_ld97t.js                    1.52 kB │ gzip:  0.69 kB
dist/client/assets/entries/entry-server-routing.xyADUdIm.js          32.65 kB │ gzip: 11.58 kB
dist/client/assets/chunks/chunk-DlFceFKS.js                          64.02 kB │ gzip: 25.81 kB

vite v6.0.8 building SSR bundle for production...
transforming...
✓ 14 modules transformed.
rendering chunks...
dist/server/package.json                                             0.02 kB
dist/server/_temp_manifest.json                                      2.05 kB
dist/server/assets/static/logo.2_7Lo9tV.svg                          5.79 kB
dist/server/assets/static/renderer_PageLayout-5d219a08.Cjl9f7UM.css  0.09 kB
dist/server/assets/static/renderer_PageLayout-83e8fff7.B8X9vkNx.css  0.38 kB
dist/server/entries/pages_about.mjs                                  1.96 kB
dist/server/entry.mjs                                                2.77 kB
dist/server/chunks/chunk-Cvd2kida.js                                 2.89 kB
dist/server/entries/pages_index.mjs                                  3.02 kB

On some project with Vike design V1, after many builds, I get the EPERM error:

vite v6.0.7 building SSR bundle for production...

✓ 107 modules transformed.
x Build failed in 920ms
Error during build:
[vike:buildConfig:pre] EPERM: operation not permitted, stat 'C:\<PROJECT>\dist\server\assets\static\layouts_styles-b42a6b89.CBLSg8Q7.D9_Axzw_.css'
    at Object.statSync (node:fs:1658:25)
    at NodeFS.statSync (C:\<PROJECT>\.pnp.cjs:13982:26)
    at makeCallSync.subPath.subPath (C:\<PROJECT>\.pnp.cjs:14522:26)
    at ZipOpenFS.makeCallSync (C:\<PROJECT>\.pnp.cjs:14996:14)
    at ZipOpenFS.statSync (C:\<PROJECT>\.pnp.cjs:14521:17)
    at VirtualFS.statSync (C:\<PROJECT>\.pnp.cjs:13663:24)
    at PosixFS.statSync (C:\<PROJECT>\.pnp.cjs:13663:24)
    at NodePathFS.statSync (C:\<PROJECT>\.pnp.cjs:13663:24)
    at removeEmptyDirectories (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js:237:21)
    at removeEmptyDirectories (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js:239:13)
    at copyAssets (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js:65:5)
    at fixServerAssets (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js:33:5)
    at Object.handler (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/plugin/plugins/buildConfig.js:100:59)
    at PluginDriver.hookParallel (file:///C:/Users/<USER>/AppData/Local/Yarn/Berry/cache/rollup-npm-4.30.1-d1a419774e-10c0.zip/node_modules/rollup/dist/es/shared/node-entry.js:20858:17)
    at file:///C:/Users/<USER>/AppData/Local/Yarn/Berry/cache/rollup-npm-4.30.1-d1a419774e-10c0.zip/node_modules/rollup/dist/es/shared/node-entry.js:21907:13
    at catchUnfinishedHookActions (file:///C:/Users/<USER>/AppData/Local/Yarn/Berry/cache/rollup-npm-4.30.1-d1a419774e-10c0.zip/node_modules/rollup/dist/es/shared/node-entry.js:21282:16)
    at buildEnvironment (file:///C:/<PROJECT>/.yarn/__virtual__/vite-virtual-56a392082f/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vite-npm-6.0.7-8c24f1f180-10c0.zip/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:50905:16)
    at Module.build (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/api/build.js:14:26)
    at cmdBuild (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/cli/entry.js:44:9)
    at cli (file:///C:/<PROJECT>/.yarn/__virtual__/vike-virtual-80ea793045/4/Users/<USER>/AppData/Local/Yarn/Berry/cache/vike-npm-0.4.218-b28558ebd7-10c0.zip/node_modules/vike/dist/esm/node/cli/entry.js:12:9) {
  errno: -4048,
  code: 'PLUGIN_ERROR',
  syscall: 'stat',
  path: 'C:\\<PROJECT>\\dist\\server\\assets\\static\\layouts_styles-b42a6b89.CBLSg8Q7.D9_Axzw_.css',
  pluginCode: 'EPERM',
  plugin: 'vike:buildConfig:pre',
  hook: 'writeBundle'
}

Solution

During the build step, prevent the creation of /dist/server/assets files.

Maybe using the generateBundle vite plugin hook, the assets/* keys can be removed from bundle object (second parameter of generateBundle).

By default, in the Vike design V1, the fix server assets is enabled (vite.build.ssrEmitAssets = true) that generates dupe assets in /dist/server/assets:

config.build.ssrEmitAssets = true

In the Vike design V1, there is any sense to generate the server assets with the fix server assets (vite.build.ssrEmitAssets = true) logic and the remove them.
Simply, in the Vike design V1, remove the fix server assets (vite.build.ssrEmitAssets = true) logic and the user, if he needs the /dist/server/assets, can add vite.build.ssrEmitAssets = true in the vite.config.

Related

@rtritto rtritto added the enhancement ✨ New feature or request label Jan 20, 2025
@brillout
Copy link
Member

Up for a PR? See node/plugin/plugins/buildConfig/fixServerAssets.ts.

@rtritto
Copy link
Contributor Author

rtritto commented Jan 20, 2025

Yes

@rtritto
Copy link
Contributor Author

rtritto commented Jan 20, 2025

@brillout by default, vite.build.ssrEmitAssets is false and Vike can also follow.

Removing the code

{
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config))
if (isServerAssetsFixEnabled) {
// https://github.com/vikejs/vike/issues/1339
config.build.ssrEmitAssets = true
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
config.build.cssMinify = 'esbuild'
fixServerAssets_assertCssTarget_populate(config)
fixServerAssets_assertCssCodeSplit(config)
}
}

the /dist/server/assets aren't generated.
The user can set vite.build.ssrEmitAssets to true if needed (I'm tested and it works).

So can we remove the vike/node/plugin/plugins/buildConfig/fixServerAssets.ts implementation because vite.build.ssrEmitAssets can handle it?

@rtritto
Copy link
Contributor Author

rtritto commented Jan 20, 2025

Created #2095

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants