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 fails with SSR turned off #27

Closed
francisfontoura opened this issue Oct 13, 2021 · 92 comments · Fixed by nuxt/framework#2191, nuxt/framework#2652 or nuxt/framework#2708
Closed

Build fails with SSR turned off #27

francisfontoura opened this issue Oct 13, 2021 · 92 comments · Fixed by nuxt/framework#2191, nuxt/framework#2652 or nuxt/framework#2708
Labels

Comments

@francisfontoura
Copy link

Environment

  • Operating System: Linux
  • Node Version: v14.18.0
  • Nuxt Version: 2.16.0-27226092.034b9901
  • Package Manager: Yarn
  • Bundler: Webpack
  • User Config: ssr, buildModules
  • Runtime Modules: -
  • Build Modules: @nuxt/bridge@3.0.0-27234503.d5127e9

Describe the bug and expected behavior

nuxi build fails with ssr: false. Output:

start Building server...                                                                                                                                               00:26:02

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


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

Steps to reproduce

  1. Set ssr: false in nuxt.config.ts.
  2. Run (npx) nuxi build in shell.

Additional context

My project doesn't need SSR, but needs "runtime config" with environment variables injected by Node.js.

@tkofh
Copy link

tkofh commented Oct 27, 2021

This is also the case for Nuxt 3 (not bridge), should that be its own issue?

@beocaca

This comment has been minimized.

@victorberland
Copy link

Considering this issue has been open for more than a month now without any progress on the matter, does anyone maybe know of a temporary fix that may work?

@AllInOneYT
Copy link

AllInOneYT commented Nov 16, 2021

Considering this issue has been open for more than a month now without any progress on the matter, does anyone maybe know of a temporary fix that may work?

you could turn off nitro temporary

  • nuxt.config.ts
defineNuxtConfig({
   bridge: {
       nitro: false
   }
})

@vietlait
Copy link

vietlait commented Dec 2, 2021

I also have the same error :(
How to fix it???

@rodrigogs
Copy link

If it's already in version 3.0.0-27313139.1c88580, then it's still not working.

Same error as before.

@piscis
Copy link

piscis commented Dec 6, 2021

@rodrigogs with 3.0.0-27313139.1c88580 it's still broken. Building my project with ssr false leads to this:

$ nuxi build
Nuxt CLI v3.0.0-27313139.1c88580                                                         16:35:25
ℹ Vite warmed up in 3822ms                                                               16:35:30
ℹ Client built in 3915ms                                                                 16:35:30
ℹ Nitro preset is server                                                                 16:35:30
ℹ Cleaning up .output                                                                    16:35:30
start Generating public...                                                               16:35:30
✔ Generated public .output/public                                                        16:35:30
start Building server...                                                                 16:35:30

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


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

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Repo: https://github.com/piscis/nuxt-quasar-boilerplate/tree/example/ssr-fix-testing

@AjaiKN
Copy link

AjaiKN commented Dec 6, 2021

Yeah, my pull request (#2191) doesn't seem to have actually fixed this issue. It's working in Nuxt's playground directory, but for some reason, if you actually create a project, Rollup still thinks it needs to import #build/dist/server/server.mjs.

@rodrigogs
Copy link

I think this issue should be reopened then.

@m0uka
Copy link

m0uka commented Dec 6, 2021

Same issue here, SSR disabled, clean Nuxt 3, please reopen

@pi0
Copy link
Member

pi0 commented Dec 6, 2021

I just wanted to confirm if this workaround works or not. We might need to generate stub server.mjs for spa mode.

@pi0 pi0 reopened this Dec 6, 2021
@rodrigogs
Copy link

Thank you @pi0, I can help testing it if you need. Just let me know :)

@yeliulee
Copy link

yeliulee commented Dec 10, 2021

any update on this?

@terion-name
Copy link

terion-name commented Dec 14, 2021

Same here. Build works with ssr: false and target: static only, but static output is strange and can't figure out how to properly serve it

@rodrigogs
Copy link

Same here. Build works with ssr: false and target: static only, but static output is strange and can't figure out how to properly serve it

It's not working atm

dargmuesli referenced this issue in dargmuesli/jonas-thelemann Apr 12, 2022
dargmuesli referenced this issue in dargmuesli/jonas-thelemann Apr 12, 2022
@danielroe danielroe transferred this issue from nuxt/framework Apr 13, 2022
nogic1008 added a commit to nogic1008/nuxt-ts-template that referenced this issue Apr 18, 2022
nogic1008 added a commit to nogic1008/nuxt-ts-template that referenced this issue Apr 28, 2022
@Yeganloo
Copy link

Yeganloo commented May 1, 2022

I hop fixing this bug be a priority for Nuxt team.
I know you are busy on the Nuxt3 it self but as a matter of fact Vuetify is one of most popular component frameworks for Vue and they are so slow on migrating to Vue3. Me my self am trying to replace it with pure css frameworks like tailwind but until then it is not possible for me to switch to Nuxt3. Meanwhile i have to make the hole project ready for Vue3 and Nuxt3 and it is lots of work! so i choose bridge as the best migration option. but after #320 i kinda stuck!

@HendrikJan
Copy link

I hope so too.
We are waiting for Vuetify 3 too before we can move to the real Nuxt 3 (really looking forward to that!).
Currently using nuxi dev instead of nuxi build but that's not a solution when our production goes live 🙃.

@MartinX3
Copy link

MartinX3 commented May 1, 2022

Currently we use Nuxt2 and Vuetify with the composition API package, since even the bridge doesn't work without SSR.

Just the terminal tells me everytime, that I should migrate from the composition API package to nuxt bridge.

But anyway we should wait for Vue 2.7 which is a migration release for Vue 3.

Also anyway it's not needed to rush to Vue3 as soon as possible.
Vue2/Vuetify2 are still maintained and will ease the migration for us with their next minor release on the roadmap.

@rodrigogs
Copy link

@MartinX3
Copy link

MartinX3 commented May 3, 2022

You guys should check this: https://www.youtube.com/watch?v=DE3HABBzUWY&ab_channel=RazorCXTechnologies

How does that fix building without SSR?

And if you look at the roadmap vuetufy 3 beta is still missing many components

@crazymind
Copy link

Updating @nuxt/bridge solved this issue for me (Note: I had problems running my app locally without ssr and not building – but the error was the same).

This commit on the 13. April solved it:
77db7ed

@jtc42
Copy link

jtc42 commented May 7, 2022

Updating @nuxt/bridge solved this issue for me (Note: I had problems running my app locally without ssr and not building – but the error was the same).

This commit on the 13. April solved it: 77db7ed

I upgraded to 3.0.0-27530716.c4f8671 which should include that commit but I still get the exact same error... Am I missing something?

@HendrikJan
Copy link

New reproduction with the latest version of @nuxt/bridge (npm:@nuxt/bridge-edge@^3.0.0-27530716.c4f8671):

  1. git clone git@github.com:HendrikJan/nuxt-bridge-error-demo.git
  2. npm install
  3. npx nuxi build
  4. Error: " ERROR Rollup error: Could not load /home/me/nuxt-bridge-error-demo/.nuxt/dist/server/server.mjs (imported by node_modules/@nuxt/bridge/dist/runtime/nitro/renderer.mjs): ENOENT: no such file or directory, open '/home/me/nuxt-bridge-error-demo/.nuxt/dist/server/server.mjs'"

The problem is still there.

@crazymind
Copy link

Can confirm that the nuxt generate still fails. nuxi dev is working.

I made a fork with quick fix to hardcode disable SSR. This way I was able to build my app with Netlify.
Really just a temporary fix, till the problem is solved properly.

Delete: node_modules
Delete: yarn.lock

yarn remove @nuxt/bridge-edge
yarn add --dev crazymind/bridge
yarn

Sidenote: I received another build error nitro preset was undefined after fixing the server.mjs problem. I changed the nitroconfig preset to nitro-dev in this fork. Not quite sure if this causes some security issues on prod?
preset: 'nitro-dev', // nuxt.options.dev ? 'nitro-dev' : undefined,

Hope this also works for you guys🙏

@eLvErDe
Copy link

eLvErDe commented Jun 5, 2022

Hello,

I can confirm this is not working either for me with fresh nuxt-bridge install from today, I'm rolling back.
Moreover, disabling nitro in nuxt.config.ts does not really help as it seems to generate weird file in .nuxt/dist/server and .nuxt/dist/client but nothing that looks like being ready to be deployed on a webserver.

@rvmourik
Copy link

rvmourik commented Jun 13, 2022

I created a work a round, that makes it possible to build without using a fork:

// nuxt.config.ts

import fs from 'node:fs';
import path from 'node:path';
import { defineNuxtConfig } from '@nuxt/bridge';

export default defineNuxtConfig({
  hooks: {
    'build:done': (builder) => {
      const extraFilePath = path.join(
        builder.nuxt.options.buildDir + '/dist/server',
        'server.mjs'
      );
      fs.writeFileSync(extraFilePath, 'export {};');
    }
  }
});

This will put a file in the proper directory just before rollup needs it.

@Yeganloo
Copy link

I can't believe an empty file could solve this problem!
Thanks a lot @rvmourik

@sankhagowit
Copy link

@rvmourik your solution worked for my nuxt-bridge SPA deployed on vercel.

I did then run into an error when attempting to access the app from any path that was not the root of the project - I had to install the ufo npm package the dependency was not in scope for any route of the SPA that wasn't the root for some reason but once the ufo npm package was added no problems.

@rvmourik
Copy link

@rvmourik your solution worked for my nuxt-bridge SPA deployed on vercel.

I did then run into an error when attempting to access the app from any path that was not the root of the project - I had to install the ufo npm package the dependency was not in scope for any route of the SPA that wasn't the root for some reason but once the ufo npm package was added no problems.

Yes, that was another problem I also encountered. But that has nothing to do with the server files not being present or skipped. I managed to resolve the ufo issue by adding it to a resolves in package.json and set it to 0.8.4.

Related issue #345 (comment)

@MartinX3
Copy link

MartinX3 commented Jul 7, 2022

At the end of nuxt generate it tells me

ℹ You can preview this build using node .output/server/index.mjs                                                                                                      nitro 11:06:55
Listening on http://localhost:3000/

Is that normal? The static output also is useless, because it's for SSR.
I just want a static build without SSR.

(nuxi generate doesn't work because of #365)

@MartinX3 MartinX3 mentioned this issue Jul 7, 2022
10 tasks
@MartinX3
Copy link

MartinX3 commented Jul 8, 2022

It seems like the generator generates a broken .js file in the _nuxt folder?

Uncaught SyntaxError: Invalid or unexpected token (at f1e478e.js:2:76798)

I did autoformat the file in IntelliJ and find errors like this

        reduceElements(t) {
            const e = this.Ï€ + this.p, [n, o] = r.b.sincos(t.inc), [c, m] = r.b.sincos(t.node - this.Ï€), d = new l.a
            return d.inc = Math.acos(o * this.cη+n * this.sη*
            m
        ),
            d.node = Math.atan2(n * c, this.cη*
            n * m - this.sη*
            o
        )
            +e, d.peri = Math.atan2(-this.sη*
            c, n * this.cη-o * this.sη*
            m
        )
            +t.peri, d
        }

With ssr: true and without the workaround hook I don't get this issue in my browser.

@danielroe
Copy link
Member

@MartinX3 Would you raise a new issue with a reproduction? I think there's something unique about your setup to examine.

@MartinX3
Copy link

MartinX3 commented Jul 8, 2022

@danielroe I try to locate the problem.
As far as I see it might be the usage of a pinia store causing it.

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