firebase / firebase-tools

The Firebase Command Line Tools
MIT License
3.97k stars 915 forks source link

Nuxt3 with Web Frameworks fails to init or deploy - Cannot create property 'overrides' on string #7375

Closed JamieCurnow closed 2 days ago

JamieCurnow commented 5 days ago

[REQUIRED] Environment info

firebase-tools: 13.11.4

Platform: macOS

[REQUIRED] Test case

https://github.com/JamieCurnow/firebase-web-framework-nuxt-loadNuxtConfig

[REQUIRED] Steps to reproduce

This is a fresh nuxt install that was created using npx nuxi@latest init

Open the repo. Run npm i to install deps. Run firebase init --debug Choose only Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys. Use and existing project or create a new one.

[REQUIRED] Expected behavior

Firebase init sets up the firebase project for the repo.

[REQUIRED] Actual behavior

The command fails due to a recent(ish) update in nuxt/kit.

TypeError: Cannot create property 'overrides' on string '/Users/JCGeek/Documents/Projects/firebase-tools-issue/nuxt-app'
    at loadNuxtConfig (file:///Users/JCGeek/Documents/Projects/firebase-tools-issue/nuxt-app/node_modules/@nuxt/kit/dist/index.mjs:2581:18)
    at async getConfig (/Users/JCGeek/.nvm/versions/node/v20.14.0/lib/node_modules/firebase-tools/lib/frameworks/nuxt/index.js:92:12)
    at async discover (/Users/JCGeek/.nvm/versions/node/v20.14.0/lib/node_modules/firebase-tools/lib/frameworks/nuxt/index.js:28:37)
    at async discover (/Users/JCGeek/.nvm/versions/node/v20.14.0/lib/node_modules/firebase-tools/lib/frameworks/index.js:47:32)
    at async doSetup (/Users/JCGeek/.nvm/versions/node/v20.14.0/lib/node_modules/firebase-tools/lib/init/features/hosting/index.js:54:11)
    at async init (/Users/JCGeek/.nvm/versions/node/v20.14.0/lib/node_modules/firebase-tools/lib/init/index.js:39:9)

Research

It looks like firebase-tools is calling loadNuxtConfig(dir) here and passing in dir as a string. In a recent Nuxt update that was made in PR here loadNuxtConfig now requires an object to be passed in.

Quick Fix

Downgrade nuxt to v3.11.2 - npm i nuxt@3.11.2, and explicitly install @nuxt/kit at 3.11.2 - npm i -D @nuxt/kit@3.11.2. Run firebase init and it should work.

Actual fix

Pass an object through to loadNuxtConfig() - it seems as though passing the dir through has no affect at least in firebase init.

async function getConfig(dir) {
  const { loadNuxtConfig } = await (0, utils_1.relativeRequire)(dir, "@nuxt/kit")
  return await loadNuxtConfig({})
}

I'll test a deploy and put up a PR.

JamieCurnow commented 5 days ago

PR here that fixes the issue.