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

Deploying nuxt app over netlify edge functions throws error at build #1284

Closed
officialpiyush opened this issue Jan 23, 2023 · 5 comments
Closed

Comments

@officialpiyush
Copy link

officialpiyush commented Jan 23, 2023

Reproduction

repo is private, can give access to the repository if needed

Steps to reproduce the bug

  • install and configure nuxt-vuefire module
  • make sure ssr is not set to false
  • build the application for netlify-edge / cloudflare-pages channel

This is how I configured my application

[
  'nuxt-vuefire',
  {
    auth: true,
    config: {
		// ..apiKey, authDomain, etc stuff from firebase
    },
    admin: {
      config: JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT as string),
    },
  } as VueFireNuxtModuleOptions,
]

Expected behavior

The build should be completed without any issues.

Actual behavior

The build fails with the following stack:

 ERROR                                                                                                                                                               nitro 00:56:53

1: import * as http from 'http';
2: import * as https from 'https';
3: import { once } from 'events';
            ^
4: import { JOSEError, JWKSTimeout } from '../util/errors.js';
5: import { concat, decoder } from '../lib/buffer_utils.js';


 ERROR  'once' is not exported by node_modules/.pnpm/[email protected]/node_modules/unenv/runtime/node/events/index.mjs, imported by node_modules/.pnpm/[email protected]/node_modules/jose/dist/node/esm/runtime/fetch_jwks.js

  at error (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
  at Module.error (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:12429:16)
  at Module.traceVariable (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:12788:29)
  at ModuleScope.findVariable (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:11440:39)
  at ReturnValueScope.findVariable (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:6372:38)
  at ChildScope.findVariable (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:6372:38)
  at Identifier.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:7439:40)
  at CallExpression.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
  at CallExpression.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:8935:15)
  at ArrayExpression.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
  at CallExpression.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
  at CallExpression.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:8935:15)
  at AwaitExpression.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
  at VariableDeclarator.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
  at VariableDeclaration.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
  at BlockStatement.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
  at ArrowFunctionExpression.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
  at VariableDeclarator.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
  at VariableDeclaration.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
  at Program.bind (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
  at Module.bindReferences (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:12425:18)
  at Graph.sortModules (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23062:20)
  at Graph.build (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:22940:14)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23730:13
  at async catchUnfinishedHookActions (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23126:20)
  at async rollupInternal (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23727:5)
  at async _build (node_modules/.pnpm/[email protected]/node_modules/nitropack/dist/shared/nitro.c8278d90.mjs:1404:18)
  at async node_modules/.pnpm/[email protected]_e3uo4sehh4zr4i6m57mkkxxv7y/node_modules/nuxt/dist/index.mjs:1677:9
  at async build (node_modules/.pnpm/[email protected]_e3uo4sehh4zr4i6m57mkkxxv7y/node_modules/nuxt/dist/index.mjs:2236:5)
  at async Object.invoke (node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/chunks/build.mjs:56:5)
  at async _main (node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/cli.mjs:50:20)

Additional information

The documentation mentions that SSR is partially supported, and to open an issue if we find any.
It is also noteworthy that the 2022 roadmap (#1241) mentions to explore other channels such as netlify and vercel.

I was able to build the application by removing nuxt-vuefire from nuxt modules, so the issue is from this module only.

@officialpiyush
Copy link
Author

officialpiyush commented Jan 24, 2023

came across firebase/firebase-admin-node#1801, seems like the firebase team is not planning to add support for edge runtimes anytime soon

I think this might be worth mentioning in the documentation, could save up some hunting time for people. Happy to create a PR if needed!

@officialpiyush
Copy link
Author

officialpiyush commented Jan 24, 2023

i think this would be better suited to be in https://github.com/unjs/unenv

related: unjs/unenv#54

@dosstx
Copy link

dosstx commented Aug 15, 2023

I'm having trouble getting a Nuxt app that uses Firebase to deploy using Netlify Edge. From what I read in this thread, it seems that using firebase-admin is not compatible with Netlify Edge Deno runtime? Does that mean I can not use the nuxt-vuefire module ? Please let me know if my understanding is correct.

@officialpiyush
Copy link
Author

officialpiyush commented Aug 15, 2023

I'm having trouble getting a Nuxt app that uses Firebase to deploy using Netlify Edge. From what I read in this thread, it seems that using firebase-admin is not compatible with Netlify Edge Deno runtime? Does that mean I can not use the nuxt-vuefire module ? Please let me know if my understanding is correct.

Yes I suppose, as per the issue I linked from the firebase-admin repo, another issue comment, it seems like the firebase-admin team is not planning to add edge support soon.

You can still use client side firebase features with SSR disabled afaik

@dosstx
Copy link

dosstx commented Sep 12, 2023

@posva or anyone:

Since we can't use Nuxt Vuefire on an Edge Function runtime, is there a way we can somehow still check for a user in middleware?

For instance, in the docs you have this:

// middleware/auth.ts
export default defineNuxtRouteMiddleware(async (to, from) => {
  const user = await getCurrentUser()

  // redirect the user to the login page
  if (!user) {
    return navigateTo({
      path: '/login',
      query: {
        redirect: to.fullPath,
      },
    })
  }
})

But that won't work on Edge runtimes because I think that getCurrentUser() requires Firebase Admin SDK (and runs only on Node). Is there another way to somehow check/get current user here so it doesn't require Firebase Admin ? Would the nuxt-vuefire module still be needed? Or, should I wrap the regular VueFire as a plugin and not use Nuxt-Vuefire in Nuxt for this case?

Seeking guidance. Thank you.

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

No branches or pull requests

2 participants