Skip to content

NodeInstaller fails at renameTo Node Binary with existing NodeJS version (Windows) #670

Closed
@JanThiel

Description

@JanThiel

Do you want to request a feature or report a bug?
bug

What is the current behavior?
The NodeInstaller.java fails to update an existing NodeJS version (Node.exe) using the renameTo function. The task fails. If I delete the node folder manually before running the task, the NodeJS executable is installed properly.

If the current behavior is a bug, please provide the steps to reproduce.

[INFO] --- frontend-maven-plugin:1.4:install-node-and-npm (install node and npm) @ PROJECT ---
[INFO] Node v6.12.0 was installed, but we need version v8.9.1
[INFO] Installing node version v8.9.1
[INFO] Downloading https://CORPORATE-PROXY/nodejs/v8.9.1/node-v8.9.1-win-x64.zip to C:\m2_repo\com\github\eirslett\node\8.9.1\node-8.9.1-win-x64.zip
[INFO] No proxies configured
[INFO] No proxy was configured, downloading directly
[INFO] Unpacking C:\m2_repo\com\github\eirslett\node\8.9.1\node-8.9.1-win-x64.zip into C:\PATH\TO\PROJECT\node\tmp
[INFO] Copying node binary from C:\PATH\TO\PROJECT\node\tmp\node-v8.9.1-win-x64\node.exe to C:\PATH\TO\PROJECT\node\node.exe
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:25 min
[INFO] Finished at: 2017-11-17T10:01:40+01:00
[INFO] Final Memory: 66M/495M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.4:install-node-and-npm (install node and npm) on project PROJECT: Could not install Node: Was not allowed to rename C:\PATH\TO\PROJECT\node\tmp\node-v8.9.1-win-x64\node.exe to C:\PATH\TO\PROJECT\node\node.exe -> [Help 1]

What is the expected behavior?
Either one of:

  • renameTo works as expected
  • or: Try to delete any existing executable file in advance, before copying over a new version instead of using renameTo

Please mention your frontend-maven-plugin and operating system version.
Plugin: 1.4 (haven't seen any relevant changes in the commits of 1.5 and 1.6)
OS: Windows 7 x64

Best Regards,
Jan

Activity

rejas

rejas commented on Dec 1, 2017

@rejas

Can confirm this happens on 1.6 too.

irbian

irbian commented on Jan 9, 2018

@irbian

1.1, 1.2 and 1.3 gave me a nullpointerexception like this:

Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.3:install-node-and-npm (install node and npm) on project PROJECT: Execution install node and npm of goal com.github.eirslett:frontend-maven-plugin:1.3:install-node-and-npm failed. NullPointerException

1.4, 1.6 and 1.6 gave me the was not allowed to rename

Is this related to #147 ?

gvespucci

gvespucci commented on Jan 30, 2018

@gvespucci

This happens to me, too.
Maven: 3.5.0
Plugin: 1.6
OS: Windows 10 Enterprise x64

Best Regards,
Giorgio

deepakab03

deepakab03 commented on May 10, 2018

@deepakab03

I encountered this Bug as well. For us the build was running on a windows Jenkins CI server with Maven 3.x and Plugin 1.6, and I think Windows 10 Enterprise x64..

The issue appears to be because of the existing workspace containing the previous node version with the folder name as ..blah..\node. So the new version that is downloaded cannot be renamed to this existing folder.
Workaround - For Jenkins - Specify (check) the Delete workspace before Build option for 1 build cycle, so that the workspace is deleted and the plugin downloads the Node version and renames it without any issue since no existing node folder is present. After build success, don't forget to un-check this option for faster builds. Locally - simply delete the node folder.

I am giving some steps to reproduce the same, in case this wasn't clear from earlier posts:
How to reproduce the same

  • Assuming you have a pom.xml with the install-node-and-npm and nodeVersion tag set to say v8.11.1 like:
<build>
      <plugins>
          <plugin>
              <groupId>com.github.eirslett</groupId>
              <artifactId>frontend-maven-plugin</artifactId>
              <executions>
                  <execution>
                      <id>install node and npm</id>
                      <goals>
                          <goal>install-node-and-npm</goal>
                      </goals>
                      <configuration>
                          <nodeVersion>v8.11.1</nodeVersion>                          
                          <workingDirectory>${basedir}</workingDirectory>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
      </plugins>
   </build>
  • Delete the node folder in the project folder if present.
  • Run a mvn clean install this will download the node version to the folder called node and do other stuff as specified in your pom.xml
  • Change the nodeVersion to say v8.9.1 in the pom.xml
  • Do a mvn clean install again, you should get this same error

Error:

[ERROR]
Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.6:install-node-and-npm (install node and npm) on project inline-window-ui: Could not install Node: Was not allowed to rename C:\dev\blah\ui\node\tmp\node-v8.9.1-win-x64\node.exe to C:\dev\blah\ui\node\node.exe -> [Help 1]

erikyuzwa

erikyuzwa commented on May 23, 2018

@erikyuzwa

TL;DR - use Node 8.9.4

can reproduce this issue - have tried via the Windows cmd.exe and git bash console windows, both using a normal user window and one created via "run as administrator". Same error condition(s) using the following versions of NodeJs.

  • 10.3.0 - error
  • 8.11.2 - error
  • 8.11.1 - error
  • 8.10.0 - error
  • 8.9.4 - success
DiabolusExMachina

DiabolusExMachina commented on Jul 17, 2018

@DiabolusExMachina

any news on this? This should be easy to fix and is very annoying

AlexanderEerenberg

AlexanderEerenberg commented on Jul 19, 2018

@AlexanderEerenberg

Same here =(

eirslett

eirslett commented on Jul 20, 2018

@eirslett
Owner

I don't have access to a Windows box. If anybody fixes it and creates a PR, I can merge and release it.

ghost

ghost commented on Aug 2, 2018

@ghost

this bug happened to me when node was already installed on the project but I've updraged the node version on the pom.xml. To fix it I've deleted the "node" folder and restart "maven install".

erikyuzwa

erikyuzwa commented on Aug 3, 2018

@erikyuzwa

@vacolane - this didn't work for me.

I believe I tracked down the specific code around the issue - NodeInstaller.java around L221

    this.logger.info("Copying node binary from {} to {}", nodeBinary, destination);
                if (!nodeBinary.renameTo(destination)) {
                    throw new InstallationException("Could not install Node: Was not allowed to rename "
                        + nodeBinary + " to " + destination);
                }

Figuring out how to build + test this locally, but there must be a workaround to using renameTo in this way.

DiabolusExMachina

DiabolusExMachina commented on Nov 13, 2018

@DiabolusExMachina

@eirslett this should be very easy to fix. Just delete the file before you rename it.

Just add this line to delte the node exe before you copy it.

Files.deleteIfExists(file.toPath());  //path to existing node exe
Zardoz89

Zardoz89 commented on Jan 25, 2019

@Zardoz89
Contributor

Any notices about this ? No body did a PR to fix this ?

added 2 commits that reference this issue on Mar 12, 2019

Fix eirslett#670: Use Files.move instead of File.rename to move files…

e770282

Fix eirslett#670: Use Files.move instead of File.rename to move files…

694e8fa

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @gvespucci@Zardoz89@erikyuzwa@rejas@deepakab03

      Issue actions

        NodeInstaller fails at renameTo Node Binary with existing NodeJS version (Windows) · Issue #670 · eirslett/frontend-maven-plugin