firebase-tools: Firebase functions emulator does not work with Yarn 2
[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:
yarn add @types/node -D
yarn add @types/express-serve-static-core -D
- Modify
src/index.ts
to export thehelloWorld
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
- Install Yarn 2.
- Execute
firebase init functions
from the CLI - choose a Firebase project; Typescript (Y); TSLint (Y); install dependencies (N). - Execute
yarn
to install dependencies. - 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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (10 by maintainers)
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:
Latest yarn
yarn set version from sources
In
package.json
@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.
Will take a look this week and report back. I’m not familiar with the differences between
yarn
andyarn@2
so it’ll take a moment I’m sure@ericvera I did end up here trying to make the emulator run, but I was already using the yarn serve command, which per the initial package.json resolves to
firebase emulators:start --only functions
. My yarn version is 3.2.1. Still,yarn serve
produces the error:Error: Error parsing triggers: Cannot find module 'firebase-functions'
Is it possible that new versions of yarn/Firebase CLI no longer work with this? Or perhaps it’s just because my code is set up in a monorepo? (I have tried with and without setting
installConfig.hoistingLimits
as shown below, to keep yarn from hoisting packages out of the functions directory up to the root).In any case, for me (specifically a yarn monorepo with yarn 3.2.1) I was only able to proceed by disabling Yarn PnP for the functions workspace (setting
nodeLinker: node-modules
in thefunctions/.yarnrc.yml
file), and I set the following infunctions/package.json
to keep it from hoisting anything to the root directory: