SSG build fails if cdnUrl is relative path
Environment
- Operating System: Linux
- Node Version: v20.19.0
- Nuxt Version: 3.16.2
- CLI Version: 3.24.1
- Nitro Version: 2.11.9
- Package Manager: [email protected]
- Builder: -
- User Config: compatibilityDate, devtools, app, modules
- Runtime Modules: [email protected]
- Build Modules: -
Nuxt Security Version
v2.2.0
Default setup used?
Yes, the bug happens even if the security option is not customized
Security options
Reproduction
https://stackblitz.com/edit/nuxt-starter-cgk1tr4x
Description
If the cdnURL is a relative path ('./' in my case), nuxt generate fails with a message of "Invalid URL".
Origin of the error is dist/modules.mjs line 229, where the URL constructor is called with the cdnURL. The URL constructor expects a base url but receives a relative path, so it makes sense that is fails.
But since it is totally valid to put a relative path in the Nuxt config I think it makes sense to build handling for that.
I'd volunteer to do so.
Additional context
No response
Logs
Nuxt 3.16.0 with Nitro 2.11.6 nuxi 13:52:44
ℹ Building for Nitro preset: static nuxi 13:52:46
ℹ Building client... 13:52:48
ℹ vite v6.2.1 building for production... 13:52:48
ℹ ✓ 127 modules transformed. 13:52:50
ℹ .nuxt/dist/client/manifest.json 1.06 kB │ gzip: 0.29 kB 13:52:50
ℹ .nuxt/dist/client/_nuxt/error-500.dGVH929u.css 1.88 kB │ gzip: 0.72 kB 13:52:50
ℹ .nuxt/dist/client/_nuxt/error-404.C3V-3Mc4.css 3.56 kB │ gzip: 1.10 kB 13:52:50
ℹ .nuxt/dist/client/_nuxt/entry.ofCu9KLV.css 12.41 kB │ gzip: 2.57 kB 13:52:50
ℹ .nuxt/dist/client/_nuxt/HK2FWpeB.js 3.39 kB │ gzip: 1.52 kB 13:52:50
ℹ .nuxt/dist/client/_nuxt/vFXklRtD.js 9.42 kB │ gzip: 3.76 kB 13:52:50
ℹ .nuxt/dist/client/_nuxt/BE0X1cod.js 219.43 kB │ gzip: 62.90 kB 13:52:50
ℹ ✓ built in 2.39s 13:52:50
✔ Client built in 2412ms 13:52:50
ℹ Building server... 13:52:50
ℹ vite v6.2.1 building SSR bundle for production... 13:52:50
ℹ ✓ 52 modules transformed. 13:52:51
ℹ .nuxt/dist/server/_nuxt/entry-styles.gwmBJwiU.mjs 0.08 kB 13:52:51
ℹ .nuxt/dist/server/_nuxt/error-500-styles.Cx3AJg0u.mjs 0.08 kB 13:52:51
ℹ .nuxt/dist/server/_nuxt/error-404-styles.BNmKahfp.mjs 0.08 kB 13:52:51
ℹ .nuxt/dist/server/_nuxt/welcome-styles.DNzFHZ_8.mjs 0.14 kB 13:52:51
ℹ .nuxt/dist/server/_nuxt/error-404-styles.wRz_-Rw1.mjs 0.14 kB 13:52:51
ℹ .nuxt/dist/server/_nuxt/error-500-styles.TwxDbBgG.mjs 0.14 kB 13:52:51
ℹ .nuxt/dist/server/styles.mjs 1.11 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/injections.mjs 0.11 kB │ map: 0.34 kB 13:52:51
ℹ .nuxt/dist/server/_virtual/_plugin-vue_export-helper.mjs 0.25 kB │ map: 0.12 kB 13:52:51
ℹ .nuxt/dist/server/_virtual/virtual_nuxt_REDACTED_.nuxt_fetch.mjs 0.28 kB │ map: 0.53 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/server-placeholder.mjs 0.28 kB │ map: 0.51 kB 13:52:51
ℹ .nuxt/dist/server/_virtual/virtual_nuxt_REDACTED_.nuxt_nuxt.config.mjs 0.29 kB │ map: 2.26 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/composables/payload.mjs 0.29 kB │ map: 4.92 kB 13:52:51
ℹ .nuxt/dist/server/_virtual/virtual_nuxt_REDACTED_.nuxt_middleware.mjs 0.30 kB │ map: 0.55 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/middleware/manifest-route-rule.mjs 0.35 kB │ map: 0.84 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/head/runtime/plugins/unhead.mjs 0.39 kB │ map: 1.44 kB 13:52:51
ℹ .nuxt/dist/server/_virtual/virtual_nuxt_REDACTED_.nuxt_components.plugin.mjs 0.40 kB │ map: 0.46 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/composables/manifest.mjs 0.59 kB │ map: 2.43 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/head/runtime/composables/v3.mjs 0.77 kB │ map: 2.11 kB 13:52:51
ℹ .nuxt/dist/server/_virtual/virtual_nuxt_REDACTED_.nuxt_plugins.server.mjs 0.95 kB │ map: 1.27 kB 13:52:51
ℹ .nuxt/dist/server/server.mjs 1.19 kB │ map: 3.47 kB 13:52:51
ℹ .nuxt/dist/server/app.vue.mjs 1.20 kB │ map: 0.38 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/plugins/revive-payload.server.mjs 1.26 kB │ map: 2.23 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/composables/error.mjs 1.43 kB │ map: 2.24 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/nuxt-error-page.vue.mjs 1.93 kB │ map: 2.56 kB 13:52:51
ℹ .nuxt/dist/server/error-500-styles-1.mjs.mjs 2.09 kB │ map: 0.11 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/nuxt-root.vue.mjs 2.53 kB │ map: 3.60 kB 13:52:51
ℹ .nuxt/dist/server/error-404-styles-1.mjs.mjs 3.77 kB │ map: 0.11 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/composables/router.mjs 3.82 kB │ map: 9.49 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/error-500.vue.mjs 4.47 kB │ map: 5.36 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/error-404.vue.mjs 5.35 kB │ map: 7.10 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/nuxt.mjs 6.84 kB │ map: 14.05 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/plugins/router.mjs 7.28 kB │ map: 12.78 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/nuxt-link.mjs 9.27 kB │ map: 19.68 kB 13:52:51
ℹ .nuxt/dist/server/entry-styles-1.mjs.mjs 12.66 kB │ map: 0.10 kB 13:52:51
ℹ .nuxt/dist/server/node_modules/nuxt/dist/app/components/welcome.vue.mjs 93.37 kB │ map: 101.57 kB 13:52:51
ℹ ✓ built in 1.30s 13:52:51
✔ Server built in 1313ms 13:52:51
ERROR Invalid URL 13:52:51
at new URL (node:internal/url:818:25)
at hashBundledAssets (REDACTED/node_modules/nuxt-security/dist/module.mjs:229:19)
at async REDACTED/node_modules/nuxt-security/dist/module.mjs:132:19
at async REDACTED/node_modules/nuxt/dist/shared/nuxt.B7-cu52A.mjs:4533:5
at async build (REDACTED/node_modules/nuxt/dist/shared/nuxt.B7-cu52A.mjs:7086:3)
at async Object.run (REDACTED/node_modules/@nuxt/cli/dist/chunks/build.mjs:74:5)
at async Object.run (REDACTED/node_modules/@nuxt/cli/dist/chunks/generate.mjs:33:5)
at async runCommand (REDACTED/node_modules/citty/dist/index.mjs:316:16)
at async runCommand (REDACTED/node_modules/citty/dist/index.mjs:307:11)
at async runMain (REDACTED/node_modules/citty/dist/index.mjs:445:7)
ERROR Invalid URL
Hey there,
Thanks for reporting this issue. Would you be interested in creating a PR with a fix? :)
I think we would need to support previous approach but also handle this additional case i.e.
check if the path is relative, if so handle it properly without error from the app
otherwise, do things as it was before
Let me know if I can help you somehow :)
Hey @Baroshem, I can create a PR for this, no problem. I don't know if I can do it today but I will take care of it.
Best regards, Tom
Hey @Baroshem, I have a fix ready but I need access rights to push to the repo :)
Hey @TomHeinemeyer
Sorry I missed this message!
Please create a fork of the repo and contribute like this :)
Oh well, I am new to contributing. Makes a lot of sense, I created the PR. Fyi @Baroshem