Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins (in a Docker container) - npm install fails because of ... npm WARN tar ENOENT: no such file or directory, futime

When running 'npm install' in a Jenkins Docker container I get these errors:

[INFO] --- exec-maven-plugin:1.6.0:exec (npm install) @ geosolutions ---
npm WARN tar ENOENT: no such file or directory, open '/var/jenkins_home/workspace/aproject2/node_modules/.staging/schema-utils-bdceae78/package.json'
npm WARN tar ENOENT: no such file or directory, open '/var/jenkins_home/workspace/aproject2/node_modules/.staging/schema-utils-bdceae78/README.md'
...(and many lines like) ...
npm WARN tar ENOENT: no such file or directory, futime
npm WARN tar ENOENT: no such file or directory, futime
npm WARN tar ENOENT: no such file or directory, futime
npm WARN tar ENOENT: no such file or directory, futime

No 'node_modules' are generated. Only a few in node_modules/.staging.

When going into the Jenkins Docker container, I can fix this by manually performing:

  • rm -rf node_modules
  • rm -f package-lock.json
  • npm install

The next time I have to skip the 'npm install' step, so directly start with the 'ng build'. Then everything works OK. Of couse - this is not a decent workaround. Therefore this is NOT a duplicate question.

How can I do a good 'npm install'?

In my Jenkins container I have a Node/Npm installation. Npm is 6.5 and node is either 8, 9, 10 or 11. All with the newest npm 6.5.

My Jenkins image contains this code for adding npm/nodejs to it:

RUN apt-get install -y curl \
  && curl -sL https://deb.nodesource.com/setup_9.x | bash - \
  && apt-get install -y nodejs \
  && curl -L https://www.npmjs.com/install.sh | sh

Update: Today I had the same issue at the office. Two different Jenkinsjobs start the very same Maven task with 'npm install'. One is OK, the other not. One Jenkinsjob is started via a multibranch, the other as a regular pipeline. Hmm, very strange.

I think this has to do with the operating environment, so the $PATH, environment variables, etc.

like image 258
tm1701 Avatar asked Jan 04 '19 18:01

tm1701


People also ask

How do I fix Enoent No such file or directory open?

To resolve the ENOENT warning message, you need to add a package. json file in the directory where you run the npm install command. And then run your npm install command again. This time, the warning message should not appear.

Why npm install is not working?

Broken npm installation If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).

Why do node modules go into .staging folder?

While doing npm install, inside node_modules . staging folder is getting created. Reasons: This is a temporary folder where the modules will be kept untill npm downloads all the modules specified in the package.


1 Answers

After talking to a number of experts and reading a lot of forum posts, the following is the proposed 'workaround'. Many people use the workaround. I hope you have a better solution than this one. At least, this workaround works.

Following the workaround, building Angular in Maven can go like this: first clear the workspace, especially removing the node_modules folder and the package-lock.json file. Then start the npm install and the build action.

If you are in a hurry after creating your first build, just add a property 'maven.exec.skip', and start Maven with the -P maven.exec.skip=true. Then the cleaning and npm install step are skipped ;-)

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
      <execution>
        <id>npm clear workspace</id>
        <goals>
          <goal>exec</goal>
        </goals>
        <phase>initialize</phase>
        <configuration>
          <skip>${maven.exec.skip}</skip>
          <executable>rm</executable>
          <arguments>
            <argument>-rf</argument>
            <argument>node_modules</argument>
            <argument>package-lock.json</argument>
          </arguments>
        </configuration>
      </execution>
      <execution>
        <id>npm install</id>
        <goals>
          <goal>exec</goal>
        </goals>
        <phase>initialize</phase>
        <configuration>
          <skip>${maven.exec.skip}</skip>
          <executable>npm</executable>
          <arguments>
            <argument>install</argument>
          </arguments>
        </configuration>
      </execution>
      <execution>
        <id>build Angular production code</id>
        <goals>
          <goal>exec</goal>
        </goals>
        <phase>generate-resources</phase>
        <configuration>
          <executable>npm</executable>
          <arguments>
            <argument>run</argument>
            <argument>build</argument>
            <!--<argument>&#45;&#45;prod</argument>-->
          </arguments>
        </configuration>
      </execution>
    </executions>
  </plugin>
like image 146
tm1701 Avatar answered Oct 22 '22 15:10

tm1701