question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firebase functions emulator does not work with Yarn 2

See original GitHub issue

[REQUIRED] Environment info

firebase-tools: 8.2.0

Platform: macOS

Node: 10.16.0

Yarn: 2.0.0-rc.33

[REQUIRED] Test case

When generating, installing and running a fresh Typescript version of a functions project using the firebase-tools CLI tool and Yarn 2, 20 errors are produced when executing yarn serve - 3 unique:

Cannot find module 'express-serve-static-core'.
Cannot find type definition file for 'node'.
'functions' is declared but its value is never read.

I can resolve these in the following way, but the resolution causes other errors which are not curable:

  1. yarn add @types/node -D
  2. yarn add @types/express-serve-static-core -D
  3. Modify src/index.ts to export the helloWorld function present in the comments.

This causes the following CLI output:

i  Starting emulators: ["functions"]
✔  functions: Emulator started at http://localhost:5001
i  functions: Watching "/Users/craig/dev/sandbox/firebase-functions-yarn-2" for Cloud Functions...
⚠  Error: Cannot find module '/Users/craig/dev/sandbox/firebase-functions-yarn-2/.yarn/cache/firebase-admin-npm-8.11.0-40c4d739ef-3.zip/node_modules/firebase-admin/package.json'
Require stack:
- /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js
Require stack:
- /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.module_1.Module._resolveFilename (/Users/craig/dev/sandbox/firebase-functions-yarn-2/.pnp.js:12283:54)
    at Module._load (internal/modules/cjs/loader.js:840:27)
    at Function.module_1.Module._load (/Users/craig/dev/sandbox/firebase-functions-yarn-2/.pnp.js:12160:36)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:123:32
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:4:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
⚠  Your function was killed because it raised an unhandled error.

I can confirm that the zip file ‘/Users/craig/dev/sandbox/firebase-functions-yarn-2/.yarn/cache/firebase-admin-npm-8.11.0-40c4d739ef-3.zip’ contains the path ‘node_modules/firebase-admin/package.json’.

I tried downgrading to firebase-tools v8.0.3 as per this issue to no avail.

I tried upgrading Yarn to use the latest sources version to no avail.

I tried using a newer version of Node (v12.16.3) to no avail.

I tried using a newer version of tslint (v6.1.2) to no avail.

Could be an issue with the PnP resolver (https://classic.yarnpkg.com/en/docs/pnp/troubleshooting)? Although I tried running the emulator using the following command, and the error still prevailed.

NODE_OPTIONS="--require ./.pnp.js" firebase emulators:start --only functions

I’ve created a repository containing the generated project so it’s as minimal as possible: https://bitbucket.org/cjmyles/firebase-functions-yarn-2/src. I’ve included firebase-debug.log as well as the Yarn 2 Zero Install files.

[REQUIRED] Steps to reproduce

  1. Install Yarn 2.
  2. Execute firebase init functions from the CLI - choose a Firebase project; Typescript (Y); TSLint (Y); install dependencies (N).
  3. Execute yarn to install dependencies.
  4. Execute yarn serve to see the first set of errors.

[REQUIRED] Expected behavior

Generated project should execute without issues, same as if the project’s dependencies were installed and the project executed using Yarn 1.

[REQUIRED] Actual behavior

See test case above.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ericveracommented, Mar 23, 2021

FYI, In case someone else ends up here to make the emulator run, instead of running firebase directly from the command line run it as a yarn command. After some reading, it seems yarn takes care of virtualizing node_modules if necessary.

Two things are needed:

  1. Latest yarn yarn set version from sources

  2. In package.json

{
  ...
  "scripts": {
    ...
    "start": "firebase emulators:start --project project-name"
    ...
  },
  "dependencies": {
    ...
    "exegesis": "^2.5.6",
    "firebase-tools": "^9.6.1",
    "typescript": "^4.2.3",
    "winston-transport": "^4.4.0"
  },
}
2reactions
cjmylescommented, Feb 20, 2021

@samtstern Apologies for the radio silence. Work commitments got the better of me. Thanks for debugging the issue and the work on the PRs, especially adding the warning, it’s greatly appreciated. I’m tempted to try a Lerna workspace with Yarn 1 or NPM to see if it fits the setup I need and avoids the issues with Yarn 2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Firebase-Functions with yarn2 | by Marco Pöhler | Medium
In this small demo I show you how to set up a fully functional Firebase Functions project with yarn2 using the nodeLinker setting....
Read more >
Yarn workspaces monorepo with Firebase functions failed to ...
This project structure would not work currently with the Firebase CLI. While using the emulator works by running firebase emulators:start ...
Read more >
Get started: write, test, and deploy your first functions - Firebase
To get started with Cloud Functions, try working through this tutorial, which starts with the required setup tasks and works through creating, testing, ......
Read more >
@firebase/functions | Yarn - Package Manager
The Firebase JavaScript SDK implements the client-side libraries used by applications using Firebase services. This SDK is distributed via:.
Read more >
Firebase functions cannot find module express
Works fine and dandy in the regular terminalto function? firebase ... error: Cannot find module 'firebase-admin' Ask Question Asked 2 years, 9 months...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found