Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nitro): fix rendering with ssr disabled #2191

Merged
merged 2 commits into from
Dec 6, 2021
Merged

Conversation

AjaiKN
Copy link
Contributor

@AjaiKN AjaiKN commented Nov 28, 2021

πŸ”— Linked issue

fix nuxt/bridge#27

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When using ssr: false, server.mjs doesn't exist, but Rollup gets confused because it thinks server.mjs might be imported. To fix this, I added a condition so that Rollup knows that server.mjs will never be loaded if NUXT_NO_SSR is true.

I also added code to handle the new Vite manifest format in getSPARenderer.

To test my changes, I added ssr: false to playground/nuxt.config.ts. Then, I ran npx yarn run nuxi build playground && node playground/.output/server/index.mjs.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

If NUXT_NO_SSR is true, server.mjs is never loaded, but Rollup gets
confused because it thinks server.mjs might be imported. To fix this,
we add a condition so that Rollup can infer that server.mjs is never
loaded.
@netlify
Copy link

netlify bot commented Nov 28, 2021

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: 2decee1

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/61a3233fba310a000826644d

@pi0 pi0 added the pending label Nov 29, 2021
@vietlait
Copy link

vietlait commented Dec 2, 2021

I also have the same problem :(
How to solve it :(

@Fire7
Copy link

Fire7 commented Dec 3, 2021

+1

@pi0
Copy link
Member

pi0 commented Dec 3, 2021

Sorry for delay reponse. We need to fix spa support but this PR is not a valid fix with introducing NUXT_NO_SSR environment variable. There is already an ssr: false option in nuxt.config that should be respected.

@AjaiKN
Copy link
Contributor Author

AjaiKN commented Dec 3, 2021

No worries! I didn't introduce process.env.NUXT_NO_SSR, but if I understand right, it already comes from the negation of the ssr option in nuxt.config. process.env.NUXT_NO_SSR is introduced here:

'process.env.NUXT_NO_SSR': JSON.stringify(!nitroContext._nuxt.ssr),

When I follow the functions back, it seems like nitroContext._nuxt.ssr comes from the ssr option in nuxt.config.

(process.env.NUXT_NO_SSR is also already used to decide whether to use getSPARenderer or getSSRRenderer.)

I may have misunderstood the code, though. Are there situations where NUXT_NO_SSR won't respect the ssr: false option in nuxt.config?

@rodrigogs
Copy link

Merging it should be a hell of a priority I'd say

@pi0 pi0 changed the title fix(nitro): make Nitro work with SSR off fix(nitro): fix rendering with ssr disabled Dec 6, 2021
@pi0 pi0 merged commit 1c88580 into nuxt:main Dec 6, 2021
@rodrigogs
Copy link

If it's in version 3.0.0-27313139.1c88580, then it's not fixed yet.

   β”‚   βœ– Nuxt Fatal Error                                                                                                                 β”‚
   β”‚                                                                                                                                      β”‚
   β”‚   Error: Could not load C:/Users/rodri/Workspace/project/modules/web/node_modules/.cache/nuxt/dist/server/server.mjs   β”‚
   β”‚   (imported by node_modules\@nuxt\nitro\dist\runtime\app\render.mjs): ENOENT: no such file or directory, open                        β”‚
   β”‚   'C:\Users\rodri\Workspace\project\modules\web\node_modules\.cache\nuxt\dist\server\server.mjs' 

@Fire7
Copy link

Fire7 commented Dec 6, 2021

Have it been fixed?
I'm on 3.0.0-27313139.1c88580 version and have same error on build:

 ERROR  Rollup error: Could not load project/.nuxt/dist/server/server.mjs (imported by node_modules/@nuxt/nitro/dist/runtime/app/render.mjs): ENOENT: no such file or directory, open 'project/.nuxt/dist/server/server.mjs'


 ERROR  Could not load project/.nuxt/dist/server/server.mjs (imported by node_modules/@nuxt/nitro/dist/runtime/app/render.mjs): ENOENT: no such file or directory, open 'project/.nuxt/dist/server/server.mjs'

@wangjing013
Copy link

some issues

@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build fails with SSR turned off
7 participants