Firebase-functions: Cannot deploy private packages with Node 10

Created on 15 Jan 2020  Â·  20Comments  Â·  Source: firebase/firebase-functions

Version info
node: 10.10.0 / 8.15.0
firebase-functions: 3.1.0
firebase-tools: 7.12.0

[REQUIRED] Test case
N/A

[REQUIRED] Steps to reproduce
Updating node 8.* to 10.* causes deployment errors. Firebase deploy seem to fail when:

i  functions: updating Node.js 10 (Beta) function api(us-central1)...
i  functions: updating Node.js 10 (Beta) function projector(us-central1)...

Unfortunately, an unauthorized error is given when accessing a private registry for dependencies. It seems that the .npmrc is ignored as it holds the _auth.

[REQUIRED] Expected behavior
Trying to deploy should not fail. For now, I'm still using node 8.

[REQUIRED] Actual behavior

i  functions: updating Node.js 10 (Beta) function projector(us-central1)...
âš   functions[projector(us-central1)]: Deployment error.
Build failed: {"error": {"canonicalCode": "INVALID_ARGUMENT", "errorMessage": "`npm_install` had stderr output:\nwarning ../package.json: No license field\nerror An unexpected error occurred: \"https://artifactory.persgroep.cloud/artifactory/api/npm/npm/vary/-/vary-1.1.2.tgz: Request failed \\\"401 Unauthorized\\\"\".\nnpm ERR! code ELIFECYCLE\nnpm ERR! errno 1\nnpm ERR! @ preinstall: `./install-function-dependencies`\nnpm ERR! Exit status 1\nnpm ERR! \nnpm ERR! Failed at the @ preinstall script.\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /builder/home/.npm/_logs/2020-01-15T11_47_09_141Z-debug.log\n\nerror: `npm_install` returned code: 1", "errorType": "InternalError", "errorId": "67EE7395"}}
âš   functions[api(us-central1)]: Deployment error.
Build failed: {"error": {"canonicalCode": "INVALID_ARGUMENT", "errorMessage": "`npm_install` had stderr output:\nwarning ../package.json: No license field\nerror An unexpected error occurred: \"https://artifactory.persgroep.cloud/artifactory/api/npm/npm/accepts/-/accepts-1.3.7.tgz: Request failed \\\"401 Unauthorized\\\"\".\nnpm ERR! code ELIFECYCLE\nnpm ERR! errno 1\nnpm ERR! @ preinstall: `./install-function-dependencies`\nnpm ERR! Exit status 1\nnpm ERR! \nnpm ERR! Failed at the @ preinstall script.\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /builder/home/.npm/_logs/2020-01-15T11_47_09_583Z-debug.log\n\nerror: `npm_install` returned code: 1", "errorType": "InternalError", "errorId": "1600C76E"}}
bug

Most helpful comment

We've got exactly the same issue, works fine on node 8, but node 10 deployment doesn't seem to be using the .npmrc file

All 20 comments

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

We've got exactly the same issue, works fine on node 8, but node 10 deployment doesn't seem to be using the .npmrc file

Experiencing this as well. Any updates on when it will be addressed?

hi
like to know by when this issue would be resolved. As by end of April it will needed to be. using node 10

We apologize for the delay - the Cloud Functions team is working on Node 10 support but unfortunately it is not available yet. We recommend staying on Node 8

I think this issue with private packages should be fixed in nodejs10 runtime. Could you try redeploying to nodejs10?

I'm not sure if this is exactly the same issue, but I'm having very similar problems migrating from node 8 to node 10 - tried multiple times in the last week (and over the past few months) and having the same issue: https://stackoverflow.com/questions/61962810/firebase-cloud-functions-cannot-deploy-to-node-10-upgrading-from-node-8

NB: I do not have any private packages - everything in my package.json is installed from NPM

It seems the problem is still there as of today. I have a private package used by some of my functions. Functions are all using node 10. I placed a .npmrc in functions directory. It contains something like:

//npmregistry.somewebsite.io/:_authToken=THE_TOKEN_HERE

Installing, building locally works fine. But at deploy time:

Deployment error.
Build failed: error An unexpected error occurred:
"https://npmregistry.somewebsite.io/mypackage/-/mypackage-1.2.0.tgz: 
Request failed \"401 Unauthorized\"".; Error ID: cbdcecb0

Isn't the .npmrc of functions directory supposed to be transmitted and used while deploying?

Any update on when this might be fixed??

@andieromero

We apologize for the delay - the Cloud Functions team is working on Node 10 support but unfortunately it is not available yet. We recommend staying on Node 8

Thank you for working on it. Since this bug is a blocker for us to launch a new project, I'm happy to help you.

I have couple of questions:

  • Is this a bug of only firebase-CLI/firebase functions/cloud functions itself?
  • Is there any active branch/thread/mailing list which is working on this issue?

@andieromero , unfortunately staying on node8 will break dependency of my app. Thus only way to run firebase function with node is to fix the bug, I think.

This is a VERY serious bug... I can't actually deploy and we're dead in the water. I've been working on this release for 6 months and this blocks us HARD.

Is there a way to debug this so I can see WHY it's not finding a package I'm trying to install?

@burtonator You can see your function's build logs in your project. When you deploy to Cloud Functions, which is what Firebase Functions uses, you'd see something like For Cloud Build Stackdriver Logs, visit: https://console.cloud.google.com/logs/viewer....

@hdp617 thanks. That doesn't really seem to help. It says it can't find my packages but I know they're in that repo as I installed them manually from that repo and it works. It's also showing them in the admin console too. unfortunately with npm there's no way to see which HTTP requests it's making so I have to assume it's not reading the .npmrc I'm trying to use.

What's the rationale for re-downloading the dependencies rather than just using the local node_modules and uploading that?

Could it be .npmrc not included in the function source code uploaded? What's the content of the .gcloudignore file?

What's the rationale for re-downloading the dependencies rather than just using the local node_modules and uploading that?

The rationale is that the dependencies in the local node_modules might not be built for the platform used in production.

If it's still not working, maybe you can try using local dependencies like in [0]?

[0] https://cloud.google.com/functions/docs/writing/specifying-dependencies-nodejs#including_local_nodejs_modules_as_part_of_your_deployment_package

@hdp617

he rationale is that the dependencies in the local node_modules might not be built for the platform used in production.

I'm sorry but this is not making a lot of sense to me. In what way could the files in the local node_modules be build differently ?

* removed unnecessarily hostile comment. Apologies for that. *

EDIT: Just tested with node 8, 10 and 12. 8 and 10 work but 12 fails with:

Function failed on loading user code. Error message: Code in file path/to/my/index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module '@my/private-package'

@Ranguna

The rationale is that the dependencies in the local node_modules might not be built for the platform used in production.

This is actually a good point. What this addresses is that some nodes have native modules in C/C++ that might need to be built which is something I didn't consider.

But the fact that .npmrc is ignored is a huge problem.

Part of this isn't Google's fault IMO but npm's support for registries is just broken. It probably works if you just set one and forget it but it has horrible support for swapping them, using read only tokens, etc.

Ah I see, so it boils down to native modules, that does make sense.

Was this page helpful?
0 / 5 - 0 ratings