Deploying Nuxt to Pages - path errors

Hi, During deployment, I get the following errors: [error] [nitro] Error: Could not load /opt/buildhome/repo/dist/dist/server/styles.mjs (imported by node_modules/nuxt/dist/core/runtime/nitro/renderer.js): ENOENT: no such file or directory, open '/opt/buildhome/repo/dist/dist/server/styles.mjs' [error] Could not load /opt/buildhome/repo/dist/dist/server/styles.mjs (imported by node_modules/nuxt/dist/core/runtime/nitro/renderer.js): ENOENT: no such file or directory, open '/opt/buildhome/repo/dist/dist/server/styles.mjs' The folder structure is fine (double /dist/ folder) and the files are in GitHub. The site also works fine locally. Not really sure how to investigate it. Any pointers are appreciated.
50 Replies
Chaika
Chaika7mo ago
If you're developing on Windows you can run into some funny issues because Linux is case sensitive while Windows isn't, worth a check
img
img7mo ago
Thanks! Locally I am using a Mac though. I also noticed I was getting additional errors when running different build commands. Though these path related erros always show
Chaika
Chaika7mo ago
I've never used Mac before but Google says Mac is also case insensitive. What I mean though is for example if you import a file as style.mjs and the file is actually named Style.mjs, case insensitive FS is ok with that but case sensitive like Linux would throw, has caused these issues before.
I also noticed I was getting additional errors when running different build commands. Though these path related erros always show
Locally?
img
img7mo ago
No, not locally. Locally everything is looking good
Chaika
Chaika7mo ago
Looks like it might be something with the build though and not with just imports: https://github.com/nuxt/nuxt/issues/13901 I don't know enough about Nuxt to help more then just saying try googling for that error, perhaps someone else who uses Nuxt can chime in here and help more, there's some issues about it on their Github repos that may be worth exploring. You shouldn't be pushing up dist if its the build output, should let Pages CI build that
GitHub
'nuxt dev' breaks on a fresh install with ssr: false · Issue #13901...
Environment Operating System: Windows_NT Node Version: v16.13.1 Nuxt Version: 3.0.0-rc.2 Package Manager: yarn@1.22.17 Builder: vite User Config: ssr Runtime Modules: - Build Modules: - Reproductio...
img
img7mo ago
Thanks. What do you mean by "You shouldn't be pushing up dist if its the build output, should let Pages CI build that"
Chaika
Chaika7mo ago
Any sort of Build Artifacts, caching directories, build output, etc, should be excluded from Git Instead Pages should run the build command and create the output anew
img
img7mo ago
I run build then run generate and push the generated output to GitHub, and from there deploy to Cloudflare. Am I doing it wrong?
Chaika
Chaika7mo ago
Generally, yes. Just in general it's best practice to only push the source to Git, the point of the Pages Build Environment CI/CD is that it has all of the tools/etc to build your application based on source
img
img7mo ago
All right, thanks for the tip!
Chaika
Chaika7mo ago
If you're pushing up the built version of the app though, why is nitro/build still running?
img
img7mo ago
Yeah, I am not really sure
Chaika
Chaika7mo ago
What's your build command?
img
img7mo ago
locally? npm run build then npm run generate then git commit -m then git push IN CF pages I tried npm run build and nuxt build
Chaika
Chaika7mo ago
Under the Pages Project -> Settings -> Builds & Deplotments, you can edit your Build config. You could select none and have it do nothing, if you're already building the app. To clarify what I said above, the point of only having src in Git is that its easier to work with. espec with other people, they can push changes and not have to remember to rebuild the app, etc. If it works though, it works. I am guilty of creating a Pages project just containing the output myself because getting ci/cd setup was too difficult and not worth it for that app. Ultimately whatever works best for you
IN CF pages I tried npm run build and nuxt build
That sounds redundant? Also you're running generate locally, but build on pages? What do those commands actually run? (check package.json)
img
img7mo ago
Yeah I need all the source files etc I think as I am using cf workers Thanks! I will check that "generate": "nuxt generate", "build": "nuxt build", Maybe I should run nuxt generate in Cloudflare actually. "Use the nuxi generate command to build and pre-render your application using the Nitro crawler."
Chaika
Chaika7mo ago
generate is static and build is server-side rendering Which is your intent? You're running generate locally and build twice on cf
img
img7mo ago
The intent is to build it on CF, with all source files in GutHub
Chaika
Chaika7mo ago
Right but as a fully static app (just uploading html/css/js to CF), or as a server-side rendered app?
img
img7mo ago
server side rendered app
Chaika
Chaika7mo ago
Then it sounds like to me you'd want to use nuxt build and not generate
img
img7mo ago
yep, you are right
Chaika
Chaika7mo ago
Like you said, generate pre-renders the app and outputs just the static assets well, does nuxt build work locally?
img
img7mo ago
no, it doesn't actually, locally I have to use npm run build
Chaika
Chaika7mo ago
should be the same thing in the end, you just don't have nuxt in your path but it does work and builds the ssr version of the app without issue?
img
img7mo ago
yep
Chaika
Chaika7mo ago
just to verify, in your nuxt.config file, your target is static or server?
img
img7mo ago
there is no target specified, actually
Chaika
Chaika7mo ago
should be fine, default is server
img
img7mo ago
shall I add "target" : "server", ? I see
Chaika
Chaika7mo ago
nah you're fine, it says the default is server if you replace your build command on Pages with just npm run build, and then do another commit to cause another build, any chance that works and doesn't explode?
Chaika
Chaika7mo ago
There's a preset for nuxt you can select as well
No description
img
img7mo ago
I tried that, with no difference
Chaika
Chaika7mo ago
What's the build environment version you're on? Under the Pages Project -> Settings -> Builds & Deployments -> Build System Version Should switch to v2 if you're not already on it. Otherwise the full build output log would be helpful
img
img7mo ago
Build system version: 2 (latest) Shall I just paste the log here?
Chaika
Chaika7mo ago
If it's small enough, or download it and upload it
img
img7mo ago
No description
img
img7mo ago
There are more errors here when I used that build command but the path errors are still there
Chaika
Chaika7mo ago
hmm those aren't the default, Nuxt's defaults are these:
No description
Chaika
Chaika7mo ago
trying to remember if Nuxt was the one who needed special settings for the latest version or if that got fixed
img
img7mo ago
I have tried them too, let' me do again
trying to remember if Nuxt was the one who needed special settings for the latest version or if that got fixed
I read that somewhere that it needed a file with a version, but that was an old issue
Chaika
Chaika7mo ago
It looks like at one time if you had ssr: false it would fail to generate the server.mjs https://github.com/nuxt/framework/pull/5773
img
img7mo ago
.nvmrc file I think
Chaika
Chaika7mo ago
.nvmrc is for node version Page's old image was on a really old node version by default v2 should be ok, and its better at autodetecting things This is what it picked base on your env Detected the following tools from environment: npm@9.6.7, nodejs@18.17.1
img
img7mo ago
I will try now with ssr: false, no difference 😦 Locally I have npm -v 10.2.4 node v21.4.0
JohnDotAwesome
JohnDotAwesome7mo ago
You'll want to sync your node versions. You're running a non-stable node release locally and LTS on Pages
img
img7mo ago
Thanks! Will sync them That didn't help 😦
Chaika
Chaika7mo ago
hmm you're at the edge of my limited nuxt knowledge lol The error changed though, did it not? At the start it was that it couldn't find the file, now it's 2023-12-06T17:35:01.595604Z [error] Cannot resolve "/opt/buildhome/repo/dist/dist/server/server.mjs" from "/opt/buildhome/repo/node_modules/nuxt/dist/core/runtime/nitro/renderer.js" and externals are not allowed! That looks like a dependency issue or something else If you want ssr on don't turn it off, after you updated your build config do you get that same error? Latest version of nuxt? Stop pushing up dist/or any build artifacts and delete them from Git.
img
img7mo ago
Yes, the erros change, except the path related error I'll keep digging. Thanks for your help! 👍