Deploying on AWS Amplify, NPM Error "authentication token not provided" #398
-
I am attempting to build my app from AWS Amplify. The build is created with an I have added my token which I got from Polar to the environment variables section within Amplify; I then edited the However, I still receive this error; npm ERR! 401 Unauthorized - GET https://npm.pkg.github.com/download/@capawesome-team/capacitor-nfc/6.1.0/bc14e06333969038e1193ccc7429b2f66de342bc - authentication token not provided Can anyone help? p.s. I pasted images, as I couldn't get the code formatting to work when I pasted yaml. Here is my version: 1
frontend:
phases:
preBuild:
commands:
- npm ci --cache .npm --prefer-offline
- echo "@capawesome-team:registry=https://npm.registry.capawesome.io" >> .npmrc
- echo "//npm.registry.capawesome.io/:_authToken=${CAPAWESOME_TOKEN}" >> .npmrc
build:
commands:
- npm run build
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- .npm/**/*` |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
You should set the token before running version: 1
frontend:
phases:
preBuild:
commands:
- - npm ci --cache .npm --prefer-offline
- echo "@capawesome-team:registry=https://npm.registry.capawesome.io" >> .npmrc
- echo "//npm.registry.capawesome.io/:_authToken=${CAPAWESOME_TOKEN}" >> .npmrc
+ - npm ci --cache .npm --prefer-offline
build:
commands:
- npm run build
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- .npm/**/*` Let me know if that helps. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick response! I have put those in the correct order now, but I still receive the same error. I have edited my amplify.yml to logout what is in .npmrc and it now looks like; version: 1
frontend:
phases:
preBuild:
commands:
- echo "CAPAWESOME_TOKEN=${CAPAWESOME_TOKEN}"
- echo "" > .npmrc
- cat .npmrc
- echo "@capawesome-team:registry=https://npm.registry.capawesome.io" >> .npmrc
- echo "//npm.registry.capawesome.io/:_authToken=${CAPAWESOME_TOKEN}" >> .npmrc
- cat .npmrc
- npm ci --cache .npm --prefer-offline
build:
commands:
- npm run build
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- .npm/**/*
Thank you for your help with this issue, I realise this isn't a capawesome issue so I do appreciate it |
Beta Was this translation helpful? Give feedback.
-
I think I have found the route cause of the issue... I created a brand new project from scratch, used your commands and it worked. I checked the package-lock.json "node_modules/@capawesome-team/capacitor-nfc": {
"version": "6.5.1",
"resolved": "https://npm.registry.capawesome.io/download/@capawesome-team/capacitor-nfc/6.5.1/1e5f631dabb8d7c6163731064bb3416f095c3382",
"integrity": "sha512-WeiqH2rROade61v0Y/6pBVNSCkyrk3ElVL5vGYk7gCKHjcBvP2w0z4po8eKKAcJGr3HTp19JaInPxycrXO/bVg==",
"peerDependencies": {
"@capacitor/core": "^6.0.0"
}
} But in the package-lock.json of my production app is "node_modules/@capawesome-team/capacitor-nfc": {
"version": "6.1.0",
"resolved": "https://npm.pkg.github.com/download/@capawesome-team/capacitor-nfc/6.1.0/bc14e06333969038e1193ccc7429b2f66de342bc",
"integrity": "sha512-t9ddI+BYOBLahNlYZVSGh6YrcJIYBbz3qcguMO6geNjbldb75gEkex85LBDSliT8Kpdbvbuuwh5MLoZ08WcQVQ==",
"peerDependencies": {
"@capacitor/core": "^6.0.0"
}
} Notice how the production version resolves to "npm.pkg.github.com" and the new app I created resolves to "npm.registry.capawesome.io". Out of interest, do you know why this would be? I uninstalled the "nfc" plugin, and then re-installed, which changed the package-lock to npm.registry and now the build works! Thank you for your help |
Beta Was this translation helpful? Give feedback.
-
Yes sure, I will add it as an answer here. The amplify.yml file: version: 1
frontend:
phases:
preBuild:
commands:
- echo "" >> .npmrc
- echo "@capawesome-team:registry=https://npm.registry.capawesome.io" >> .npmrc
- echo "//npm.registry.capawesome.io/:_authToken=${CAPAWESOME_TOKEN}" >> .npmrc
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- .npm/**/* I am not certain that ' echo "" >> .npmrc' is required, but it does no harm and I had a hunch it intermittently wasn't being cleared properly between builds. I add the ${CAPAWESOME_TOKEN} to the environments variable page. Here are the images, incase you want to use them in your documentation; |
Beta Was this translation helpful? Give feedback.
Yes sure, I will add it as an answer here.
The amplify.yml file:
I am not certain that ' echo "" >> .npmrc' is required, but it does no harm and I had a hunch it intermittently wasn't being cleared properly between builds.
I add the ${CAPAWESOME_TOKEN} to the env…