I have created a private typings npm module that I am using for my firebase functions and app projects. When I went to deploy firebase functions, I get a big error for every function that basically says ERR: remote. Invalid username or password.
ERR: remote. Invalid username or password.
For what I have read, it looks like I need to create a.npmrc file and put it in the /functions directory. ( https://cloud.google.com/functions/docs/writing/specifying-dependencies-nodejs#using_private_modules )
I cannot however find proper instructions on how to do this anywhere. From what I found, I have done the following:
This then gave me a token that looks like this: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
.
I then create a file called.npmrc in my functions directory, and placed //registry.npmjs.org/:_authToken=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
in it.
Additionally, I saw that the error message was trying to use ssh to install my private repo package, I have not setup ssh and am using https instead, because of this I changed my package file to git+https://github.com/accounts-name/repo#commit-num
so that it uses HTTPS.
However, I still get the same error message. What am I missing? The above is what I have strung together from lots of google searching.
It seems that you have made too many different changes while trying to make it work, so let's just go through the whole process step by step.
Check the package.json of your npm module and publish it:
false
because private modules in the npm are meant to be never published. That is not obvious but that is true.package.json
file: "publishConfig": { "access": "restricted" },
npm
account you use for publishing supports private packages.npm login
then sign in to npm. Check if you put the proper version in the package.json
.npm publish
. The package should be published in few seconds. No worries, thanks to publishConfig
property nobody can access it.Now it is time to allow package installation in your project
package.json
file dependencies
listtokens
tabpackage.json
file is situated (that is important!) and create .npmrc
file there..npmrc
file: //registry.npmjs.org/:_authToken=TOKEN_HERE
You are done!
Deployment with remote CI/CD services
.npmrc
into .gitignore
. In such case the file will be always in repository, so npm install
will run smoothly on any machine where project was clonedNPM_TOKEN
env variable (Just token from npmjs, not the whole string from.npmrc!) And then change the .npmrc
file in the next way: //registry.npmjs.org/:_authToken=${NPM_TOKEN}
.So, with those steps you should be able to install your restricted packages without any issues. Good luck!
If you are trying to deploy you functions with firebase deploy from a CI and your .npmrc
file looks like this.
@acmecorp:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=${NPM_REGISTRY_TOKEN}
You will run into the problem even if you have the env var set.
Build failed: Error: Failed to replace env in config: ${NPM_REGISTRY_TOKEN}
Firebase for some reason needs access to that private repo. But the env var is not sent over to firebase.
Solution I've implemented was to replace ${NPM_REGISTRY_TOKEN}
in the.npmrc file on every run of the CI pipeline.
sed -i.bak "s/\${NPM_REGISTRY_TOKEN}/${NPM_REGISTRY_TOKEN}/g" .npmrc
This breaks if you use Yarn . Took me a while to find a thread pointing to npm install in the firebase cli predeploy step. If there's no package-lock.json and you only use yarn, this will break. Remove yarn.lock and install using npm to resolve the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.