I am trying to create a build pipeline in Azure DevOps for my create-react-app project. However, when I run it I am getting the below error message during the npm install and build job.
2020-11-16T16:38:47.9641910Z npm ERR! Only absolute URLs are supported
2020-11-16T16:38:47.9906864Z
2020-11-16T16:38:47.9908747Z npm ERR! A complete log of this run can be found in:
2020-11-16T16:38:47.9910292Z npm ERR! /home/vsts/.npm/_logs/2020-11-16T16_38_47_983Z-debug.log
2020-11-16T16:38:48.2879019Z
2020-11-16T16:38:48.2879989Z > allpointsui#1.0.0 build /home/vsts/work/1/s
2020-11-16T16:38:48.2881040Z > react-scripts build
2020-11-16T16:38:48.2881441Z
2020-11-16T16:38:48.2927383Z sh: 1: react-scripts: not found
2020-11-16T16:38:48.2967162Z npm ERR! code ELIFECYCLE
2020-11-16T16:38:48.2968631Z npm ERR! syscall spawn
2020-11-16T16:38:48.2969062Z npm ERR! file sh
2020-11-16T16:38:48.2971442Z npm ERR! errno ENOENT
2020-11-16T16:38:48.2983381Z npm ERR! allpointsui#1.0.0 build: `react-scripts build`
2020-11-16T16:38:48.2983876Z npm ERR! spawn ENOENT
2020-11-16T16:38:48.2984513Z npm ERR!
2020-11-16T16:38:48.2984827Z npm ERR! Failed at the allpointsui#1.0.0 build script.
2020-11-16T16:38:48.2985278Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-16T16:38:48.3029598Z
2020-11-16T16:38:48.3032027Z npm ERR! A complete log of this run can be found in:
2020-11-16T16:38:48.3033461Z npm ERR! /home/vsts/.npm/_logs/2020-11-16T16_38_48_298Z-debug.log
2020-11-16T16:38:48.3150378Z ##[error]Bash exited with code '1'.
2020-11-16T16:38:48.3205602Z ##[section]Finishing: npm install and build
Here is my YAML file for the pipeline.
trigger:
-master
pool:
`vmImage: 'ubuntu-latest`
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
To resolve the error, I have tried doing npm i and npm audit fix which installed react-scripts4.0 but the error is still occurring. I have also seen a lot of people suggesting in other posts to delete the package-lock.json but we would prefer not do do that. Just another note: I can successfully run a build of the project on my local computer. Any suggestions or ideas of how to resolve this issue? Thank you in advance!
react-scrips: not found - Azure DevOps build pipeline
First, try to check if node_modules directory exists in the Azure repo, if yes, remove it and then run npm install and build.
Second, add the entire path in the package.json to invoke react-scripts:
"start": "node_modules/react-scripts/bin/react-scripts.js start"
Instead of just: "start": "react-scripts start".
If above not resolve your question, try to share your package.json in your question.
Related
I am trying to setup actions for NextJS app using the following yml file
name: Frontend Build
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: "18"
- run: |
cd frontend
npm ci
npm run build
but i get the error every time npm ci or npm install is run
It says :
Run cd frontend
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2023-02-18T16_14_12_437Z-debug-0.log
Error: Process completed with exit code 1.
i did not see anyone setting password for public npm registry.
Thanks in advance
You have to create an .npmrc file with proper authToken when installing a secured dependencies.
name: "Create .npmrc"
run: |
echo "registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
Then you can call npm install.
I am using semantic version action on my GitHub enterprise repository. It was working fine until recently, where it started failing with this error
Error: Command failed: npm ci --only=prod
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-08-23T10_41_00_344Z-debug.log
at ChildProcess.exithandler (child_process.js:295:12)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
killed: false,
code: 1,
signal: null,
cmd: 'npm ci --only=prod',
stdout: '',
stderr: 'npm ERR! code E401\n' +
'npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"\n' +
'\n' +
'npm ERR! A complete log of this run can be found in:\n' +
'npm ERR! /root/.npm/_logs/2021-08-23T10_41_00_344Z-debug.log\n'
The action I use is not expected to publish anything to GitHub Package Registry, maybe only read from Package Registry. So after googling I found this on SO and elsewhere - https://stackoverflow.com/a/63243950/1182982
So I updated my action to look like this now (I added the step: Setup node, it wasn't there before)
#===============================================================================
#=========================== Semamtic Version ==========================
#===============================================================================
semver:
name: Semantic Versioning
runs-on: [self-hosted, linux, x64]
steps:
- name: Setup node
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUBCOM_TOKEN }}" >> ~/.npmrc
echo "#yrshaikh:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo 'registry "https://registry.yarnpkg.com"' >> ~/.yarnrc
- uses: actions/checkout#v2
- name: Semantic Release
id: semantic
# https://github.com/cycjimmy/semantic-release-action
uses: internal-front-end/semantic-release-action#v2
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
Note, the GITHUBCOM_TOKEN I created using my github.com personal profile (And gave read packages/repo access) and OWNER_NAME in #yrshaikh:registry=https://npm.pkg.github.com I have filled in github.com user id.
After doing these changes the 401 authentication error has gone.
But I see a different error, which I have not been able to resolve -
Error: Command failed: npm --loglevel error ci --only=prod
npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/#actions%2fcore - npm package "core" does not exist under owner "actions"
npm ERR! 404
npm ERR! 404 '#actions/core#1.2.7' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-08-25T05_40_28_115Z-debug.log
at ChildProcess.exithandler (child_process.js:295:12)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
killed: false,
code: 1,
signal: null,
cmd: 'npm --loglevel error ci --only=prod',
stdout: '',
stderr: 'npm ERR! code E404\n' +
'npm ERR! 404 Not Found - GET https://npm.pkg.github.com/#actions%2fcore - npm package "core" does not exist under owner "actions"\n' +
'npm ERR! 404 \n' +
"npm ERR! 404 '#actions/core#1.2.7' is not in the npm registry.\n" +
'npm ERR! 404 You should bug the author to publish it (or use the name yourself!)\n' +
'npm ERR! 404 \n' +
'npm ERR! 404 Note that you can also install from a\n' +
'npm ERR! 404 tarball, folder, http url, or git url.\n' +
'\n' +
'npm ERR! A complete log of this run can be found in:\n' +
'npm ERR! /root/.npm/_logs/2021-08-25T05_40_28_115Z-debug.log\n'
}
Any help or direction will be appreciated.
There doesn't seem to be anything wrong about the ~/.npmrc:
#${OWNER}:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${TOKEN}
Have you tried to regenerate that personal access token? Be aware that these secrets also have scopes, so they may resolve in a private repository, but not necessarily a public repository.
$GITHUB_TOKEN may not have sufficient permissions; try adding a personal access token instead.
What does npm login --scope=#yrshaikh --registry=https://npm.pkg.github.com give?
I would like to ask how can I implement the ESLint on our Azure Pipeline? I do not have enough knowledge on Azure Pipelines and SonarQube, and I also am not so sure about ESLint. So far, here's the script I have. Although this is pretty much from the available tasks. I'd like to implement the ESLint on SonarQube like on this link: https://docs.sonarqube.org/pages/viewpage.action?pageId=11639183
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
checkLatest: true
displayName: 'Install Node.js'
- task: Npm#1
inputs:
command: 'install'
displayName: 'NPM Install'
- script: |
npm bin -g
displayName: 'Check path'
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'test' #from the package.json
This one here is from the npm bin -g:
##[debug] /home/vsts/work/_temp/5b2e34ae-e8f8-4e24-a539-9d41f7435789.sh
/bin/bash --noprofile --norc /home/vsts/work/_temp/5b2e34ae-e8f8-4e24-a539-9d41f7435789.sh
/opt/hostedtoolcache/node/10.23.1/x64/bin
##[debug]Exit code 0 received from tool '/bin/bash'
##[debug]STDIO streams have closed for tool '/bin/bash'
##[debug]task result: Succeeded
##[debug]Processed: ##vso[task.complete result=Succeeded;done=true;]
Here's the error from the last task.
##[debug]Agent.BuildDirectory=/home/vsts/work/1
##[debug]rm -rf /home/vsts/work/1/npm
##[debug]removing directory
##[debug]task result: Failed
##[error]Error: Npm failed with return code: 1
##[debug]Processed: ##vso[task.issue type=error;]Error: Npm failed with return code: 1
##[debug]Processed: ##vso[task.complete result=Failed;]Error: Npm failed with return code: 1
Here's a bit of copy from my package.json:
"scripts": {
"lint": "npm run lint:lwc && npm run lint:aura",
"linter": "./node_modules/.bin/eslint ./",
"lint:aura": "eslint **/aura/**",
"lint:lwc": "eslint **/lwc/**",
"test": "npm run test:unit",
There is not tasks or commands in your yaml pipeline to run the linter. You can add a script task or npm task to run the linter. See below:
Add a npm task to run linter.
- task: Npm#1
inputs:
command: 'install'
displayName: 'NPM Install'
- task: Npm#1
displayName: 'Linter'
inputs:
command: 'custom'
customCommand: 'run linter'
Or add a script task to run linter:
- task: Npm#1
inputs:
command: 'install'
displayName: 'NPM Install'
- script: |
npm run linter
npm run lint #run npm run lint:lwc && npm run lint:aura in your package.json
Before you can run above linter commands in azure pipeline. You need to add eslint dependency to your project and generate your ESLint config file on your local machine.
Run below commands on your local repo and then push to your source server.
Add eslint dependency:
npm install eslint --save-dev
Generate ESLint config file
./node_modules/.bin/eslint --init
You can check out this blog.
I'm trying to run a cypress test in an Azure Pipeline job using YAML. When the pipeline runs, it gets to the line where the cypress test runs and throws this error:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\myagent\_work\5\s\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\myagent\_work\5\s\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
Here is my YAML file:
trigger:
- master
pool:
name: Default
variables:
buildConfiguration: 'Release'
steps:
- task: NodeTool#0
displayName: 'Use Node 12.x'
inputs:
versionSpec: 12.18.3
checkLatest: false
- task: Npm#1
displayName: 'npm install'
inputs:
workingDir: WebApp
verbose: false
- task: Npm#1
displayName: 'Build Angular'
inputs:
command: custom
customCommand: run build -- --prod
workingDir: WebApp
- task: UseDotNet#2
displayName: 'Use .NET Core SDK 3.1.300'
inputs:
packageType: sdk
version: 3.1.300
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: AppApi/AppApi.csproj
vstsFeed: '*************'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: publish
arguments: '--no-restore --configuration $(buildConfiguration) --verbosity quiet --output $(build.artifactstagingdirectory)'
publishWebProjects: true
zipAfterPublish: true
- script: 'npx cypress verify'
displayName: 'cypress verify'
failOnStderr: true
- script: 'npm run cy:run --headless --spec cypress/integration/TestDemoExpanded.spec.ts --project ./WebApp'
displayName: 'run cypress tests'
workingDirectory: $(Build.SourcesDirectory)/WebApp
My package.json is checked into my Git repository and is located in my WebApp subfolder. How do I solve this error?
UPDATED:
I added the workingDirectory parameter as suggested but now I have this new error: npm ERR! missing script: cypress
I solved the 'missing script' error. The cypress run command I had in my YAML file didn't match the cypress run command I had in my package.json. I updated the cypress run step and now the tests run in the pipeline.
The task searches the package.json in the root folder and not in WebApp.
Just add:
workingDirectory: $(Build.SourcesDirectory)/WebApp
To the cypress step:
- script: 'npm run cypress run --headless --spec cypress/integration/TestDemoExpanded.spec.ts --project ./WebApp'
displayName: 'run cypress tests'
workingDirectory: $(Build.SourcesDirectory)/WebApp
I have a CI/CD process with gitlab ci for ionic app deployment for auto content update using this gitlab-ci.yml
image: cypress/base:10
stages:
- build
before_script:
- rm -rf node_modules
- npm install
- npm install -g tslint typescript
build_app:
stage: build
artifacts:
paths:
- /myApp/myApp-app/cypress/screenshots/
- /myApp/myApp-app/cypress/videos/
expire_in: 1 week
when: always
script:
# run tslint
- tslint --project tsconfig.json --config tslint.json
- npm run e2e
The above step is used for build. But build is getting failed with the below error.
starting server using command "ionic:serve"
and when url "http-get://localhost:8100" is responding
running tests using command "npm run cypress:run"
/bin/sh: 1: ionic:serve: not found
Error: server closed unexpectedly
at ChildProcess.onClose (/builds/myApp-ai/myApp-app/node_modules/start-server-and-test/src/index.js:68:14)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:962:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mapsit-app#0.0.1 e2e: `start-server-and-test ionic:serve http-get://localhost:8100 cypress:run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mapsit-app#0.0.1 e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-09-08T05_50_39_435Z-debug.log
Uploading artifacts...
WARNING: /myApp/myApp-app/cypress/screenshots/: no matching files
WARNING: /myApp/myApp-app/cypress/videos/: no matching files
ERROR: No files to upload
ERROR: Job failed: exit code 1