Skip to content

fix(firebase): could not find functions.yaml - #627

Closed
DevJoghurt wants to merge 6 commits into
nitrojs:mainfrom
DevJoghurt:main
Closed

DevJoghurt wants to merge 6 commits into
nitrojs:mainfrom
DevJoghurt:main

Conversation

@DevJoghurt

Copy link
Copy Markdown

🔗 Linked issue

nuxt/framework#236

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • [x ] 🐞 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

Problem was described in this issue nuxt/framework#236

For internal reasons Firebase cli calls a node script 'spawn ./node_modules/.bin/firebase-functions'.
Nitro cannot know about this and does not copy the necessary files via '@vercel/nft'.
I have written a small function that copies all the missing necessary files so that the deployment can be performed.

📝 Checklist

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

@DevJoghurt

Copy link
Copy Markdown
Author

@aaronjsutton

Copy link
Copy Markdown

@DevJoghurt Awesome! I also just fixed this issue and wrote the exact same helper function. Was about to submit a PR, guess I don't have to!

@danielroe danielroe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - thank you!

Would you try instead whether it's possible to include these files by adding them to the externals.traceInclude array rather than running a manual copy?

@codecov

codecov Bot commented Dec 2, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #627 (28fb788) into main (c1cf5ce) will decrease coverage by 10.54%.
The diff coverage is 0.00%.

❗ Current head 28fb788 differs from pull request most recent head 4c8f830. Consider uploading reports for the commit 4c8f830 to get more accurate results

@@             Coverage Diff             @@
##             main     #627       +/-   ##
===========================================
- Coverage   76.89%   66.35%   -10.54%     
===========================================
  Files          68       57       -11     
  Lines        6829     4182     -2647     
  Branches      693      446      -247     
===========================================
- Hits         5251     2775     -2476     
+ Misses       1577     1403      -174     
- Partials        1        4        +3     
Impacted Files Coverage Δ
src/presets/firebase.ts 32.40% <0.00%> (+14.38%) ⬆️

... and 55 files with indirect coverage changes

@DevJoghurt

Copy link
Copy Markdown
Author

@danielroe
Thanks for your review.
I tried to include 'firebase-functions' by something like this:

export const firebase = defineNitroPreset({
  entry: '#internal/nitro/entries/firebase',
  externals: {
    traceInclude: ['firebase-functions/lib/bin/firebase-functions.js']
  },
  commands: {
    deploy: 'npx firebase deploy'
  },
  hooks: {
    async 'compiled' (ctx) {
      //resolveRequiredNodeModules(ctx)
      await writeRoutes(ctx)
    }
  }
})

It is failing with the following error:
Could not resolve import "firebase-functions/lib/bin/firebase-functions.js" in undefined using exports defined in /Users/XXX/Documents/Code/nitro/node_modules/firebase-functions/package.json.

I think the problem is that the firebase cli needs the following file to work correctly: node_modules/.bin/firebase-functions.
This file links to 'firebase-functions/lib/bin/firebase-functions.js'. This is defined as a binary and not as an export in package.json.
I'm not sure if this can be done by tracing. What do you think?

@pi0
pi0 requested a review from danielroe January 16, 2023 13:28
@pi0 pi0 changed the title Fix(Firebase Deployment): Could not find functions.yaml fix(firebase): could not find functions.yaml Jan 16, 2023
@pi0

pi0 commented May 17, 2023

Copy link
Copy Markdown
Member

Kind reminder for review @danielroe

If it is not relevant anymore or you think an alternative method could be better, would be happy to move it to an issue to track.

@danielroe

Copy link
Copy Markdown
Member

Apologies - I missed this.

@DevJoghurt I think you can pass paths to binaries as well - they just need to be full paths (that is, including node_modules). Would you try?

@DevJoghurt

Copy link
Copy Markdown
Author

Apologies - I missed this.

@DevJoghurt I think you can pass paths to binaries as well - they just need to be full paths (that is, including node_modules). Would you try?

Sure, I'll give it a try and then give you feedback.

@DevJoghurt

Copy link
Copy Markdown
Author

@danielroe
Ok, this seems to work in general. Unfortunately, in the firebase-functions.js file the first line is like this: '#!/usr/bin/env node'. This seems to cause a problem with '@rollup/plugin-inject'. Tried to exclude the file via exclude, but this was not possible with the current config options in nitro.
Do you have any idea what else I can try?

@Hebilicious Hebilicious added bug Something isn't working (PRs; issues use the Bug type) preset:firebase labels Jun 30, 2023
@Hebilicious

Hebilicious commented Jul 1, 2023 •

Copy link
Copy Markdown
Contributor

@DevJoghurt , could you please provide a reproduction ? from my latest tests with nitro and nuxt, the firebase preset works for me without additional modifications, see here #1370

If this fixes #628 or an untracked bug, then this is fine

@Hebilicious Hebilicious added pending Blocked on an upstream change or a decision needs reproduction Needs a minimal reproduction to move forward labels Jul 1, 2023
@DevJoghurt

Copy link
Copy Markdown
Author

Yes, that is correct. It seems to work with the latest firebase cli version.
So I will close the pull request now.

@DevJoghurt DevJoghurt closed this Jul 3, 2023

This branch was successfully deployed

1 active deployment
Preview — 4c8f8302 Deployed May 17, 2023 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working (PRs; issues use the Bug type) needs reproduction Needs a minimal reproduction to move forward pending Blocked on an upstream change or a decision preset:firebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants