Getting CI/CD error on biulding step in React Azure Pipeline

82 Views Asked by At

i'm facing with the pipeline job when my app is trying to build the react app. I tried changing the build command adding CI= xxxxx, also I tried to updating the dependeces, resolve warnings and I checked the path for server app and client app.

This is the complete job that I have(https://i.stack.imgur.com/njxLS.png) This is my project tree(https://i.stack.imgur.com/4KG1l.png)

This is my azure-pipelines.yml

# Node.js with React
# Build a Node.js project that uses React.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- task: Npm@1
  displayName: "Installing modules in /Server"
  inputs:
    command: 'install'
    workingDir: 'Server/IglesiaFiel.WebAPI'
- task: Npm@1
  displayName: "Installing modules in /Client"
  inputs:
    command: 'install'
    workingDir: 'Client/iglesiafiel.front'
- task: Npm@1
  displayName: "Building modules in /Client"
  inputs:
    command: 'custom'
    workingDir: 'Client/iglesiafiel.front'
    customCommand: 'run build'
- task: CopyFiles@2
  inputs:
    Contents: |
      Client/iglesiafiel.front/build/**
      Sertver/IglesiaFiel.WebAPI/**
    TargetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'release'
    publishLocation: 'Container'

This is the entire log:

1 verbose cli   '/opt/hostedtoolcache/node/10.24.1/x64/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~build: PATH: /opt/hostedtoolcache/node/10.24.1/x64/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/vsts/work/1/s/Client/iglesiafiel.front/node_modules/.bin:/opt/hostedtoolcache/node/10.24.1/x64/bin:/snap/bin:/home/vsts/.local/bin:/opt/pipx_bin:/home/vsts/.cargo/bin:/home/vsts/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/vsts/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle [email protected]~build: CWD: /home/vsts/work/1/s/Client/iglesiafiel.front
10 silly lifecycle [email protected]~build: Args: [ '-c', 'CI= react-scripts build' ]
11 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] build: `CI= react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/opt/hostedtoolcache/node/10.24.1/x64/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/opt/hostedtoolcache/node/10.24.1/x64/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid [email protected]
15 verbose cwd /home/vsts/work/1/s/Client/iglesiafiel.front
16 verbose Linux 6.5.0-1016-azure
17 verbose argv "/opt/hostedtoolcache/node/10.24.1/x64/bin/node" "/opt/hostedtoolcache/node/10.24.1/x64/bin/npm" "run" "build"
18 verbose node v10.24.1
19 verbose npm  v6.14.12
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] build: `CI= react-scripts build`
22 error Exit status 1
23 error Failed at the [email protected] build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

##[error]Error: Npm failed with return code: 1
Finishing: Building modules in /Client

1

There are 1 best solutions below

0
Kevin Lu-MSFT On

From your screenshot, the project contains the node_modules folder in the repo.

enter image description here

The current issue could be related to NPM cache.

You can remove the node_modules directory and package-lock.json file in the project.

Then you can use Pipeline to run npm install to fresh install all packages.

For exmaple:

- task: Npm@1
  displayName: "Installing modules in /Client"
  inputs:
    command: 'install'
    workingDir: 'Client/iglesiafiel.front'