<p>I tried everything to build a ReactJs app with NPM in a Jenkins pipeline running on Kubernetes.</p>
<p>When I try to build my project from Windows or even from Windows subsystem for Linux with an Ubuntu installation, everything work fine and NPM is able to install the packages and build de project from the package.json file.</p>
<p>I installed the NodeJS Plugin (available <a href="https://plugins.jenkins.io/nodejs/" rel="nofollow noreferrer">here</a>)
And I add this section to my Jenkinsfile</p>
<pre><code>stages {

    stage('Build') {

        steps {

            nodejs(nodeJSInstallationName: 'nodeJS_14.15.4') {

                sh &quot;&quot;&quot;
                cd ./project-folder
                npm install
                npm run-script build
                &quot;&quot;&quot;
            }
        }
    }
}
</code></pre>
<p>I use the following <strong>package.json</strong></p>
<pre><code>{
    &quot;name&quot;: &quot;app-react&quot;,
    &quot;version&quot;: &quot;5.0.0&quot;,
    &quot;homepage&quot;: &quot;.&quot;,
    &quot;private&quot;: true,
    &quot;dependencies&quot;: {
        &quot;react&quot;: &quot;^17.0.1&quot;,
        ...
        &quot;react-scripts&quot;: &quot;4.0.0&quot;,
        ...
    },
    &quot;scripts&quot;: {
        &quot;start&quot;: &quot;set HTTPS=true&amp;&amp;react-scripts start&quot;,
        &quot;build&quot;: &quot;set GENERATE_SOURCEMAP=false&amp;&amp;react-scripts build&quot;,
        &quot;test&quot;: &quot;react-scripts test&quot;,
        &quot;eject&quot;: &quot;react-scripts eject&quot;,
        &quot;sitemap&quot;: &quot;babel-node src/sitemap-generator.js&quot;
    },
    &quot;eslintConfig&quot;: {
        &quot;extends&quot;: &quot;react-app&quot;
    },
    &quot;browserslist&quot;: [
        &quot;&gt;0.2%&quot;,
        &quot;not dead&quot;,
        &quot;not ie &lt;= 11&quot;,
        &quot;not op_mini all&quot;
    ],
    &quot;devDependencies&quot;: {
        &quot;babel-cli&quot;: &quot;^6.26.0&quot;,
        &quot;babel-preset-es2015&quot;: &quot;^6.24.1&quot;,
        &quot;babel-preset-react&quot;: &quot;^6.24.1&quot;
    }
}
</code></pre>
<p>The installation seems to be ok, but then it always fails at the build step. With blue ocean I can see the following error message</p>
<pre><code>npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! apollo-react@5.0.1 build: `set GENERATE_SOURCEMAP=false&amp;&amp;./node_modules/react-scripts/bin/react-scripts.js build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the apollo-react@5.0.1 build 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/2021-12-04T19_05_34_235Z-debug.log
script returned exit code 1
</code></pre>
<p>The full logs accessible into /root/.npm/_logs show me this :</p>
<pre><code>0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run-script', 'build' ]
2 info using npm@6.14.10
3 info using node@v14.15.4
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle app-react@5.0.0~prebuild: app-react@5.0.0
6 info lifecycle app-react@5.0.0~build: app-react@5.0.0
7 verbose lifecycle app-react@5.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle app-react@5.0.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/jenkins/agent/workspace/client/app-react/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle app-react@5.0.0~build: CWD: /home/jenkins/agent/workspace/client/app-react
10 silly lifecycle app-react@5.0.0~build: Args: [ '-c', 'set GENERATE_SOURCEMAP=false&amp;&amp;react-scripts build' ]
11 silly lifecycle app-react@5.0.0~build: Returned: code: 1  signal: null
12 info lifecycle app-react@5.0.0~build: Failed to exec build script
13 verbose stack Error: app-react@5.0.0 build: `set GENERATE_SOURCEMAP=false&amp;&amp;react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.&lt;anonymous&gt; (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.&lt;anonymous&gt; (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1048:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid app-react@5.0.0
15 verbose cwd /home/jenkins/agent/workspace/client/app-react
16 verbose Linux 4.15.0-135-generic
17 verbose argv &quot;/usr/local/bin/node&quot; &quot;/usr/local/bin/npm&quot; &quot;run-script&quot; &quot;build&quot;
18 verbose node v14.15.4
19 verbose npm  v6.14.10
20 error code ELIFECYCLE
21 error errno 1
22 error app-react@5.0.0 build: `set GENERATE_SOURCEMAP=false&amp;&amp;react-scripts build`
22 error Exit status 1
23 error Failed at the app-react@5.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
</code></pre>
<p>Before that I also tried to build my project with other agents, actually in my script before that test with the NodeJs plugin, I used Kubernetes plugin that can run any agent into a temporary pod. So I tried with a Nodejs image, even with an Ubuntu image in which one I installed NodeJs manually. The result is always the same then before.</p>
<p>I don't know what is the source of the problem: the access to the installed packages? A resource problem?</p>

<p>I finally found a workaround. The build fail not because of errors but warnings.</p>
<p>The workaround is to remove the eslint configuration part</p>
<pre><code>&quot;eslintConfig&quot;: {
    &quot;extends&quot;: &quot;react-app&quot;
}
</code></pre>
<p>When eslint is not active the result of the build is <strong>Compiled successfully</strong>.</p>
<p>But when it is active the result is <strong>Compiled with warnings</strong> and all the warnings appear in the logs, and the jenkins job fail.</p>
