Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JanThiel opened this issue Nov 17, 2017 · 12 comments · Fixed by #801
Closed

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

JanThiel opened this issue Nov 17, 2017 · 12 comments · Fixed by #801

Comments

@JanThiel
Copy link

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

@rejas
Copy link

rejas commented Dec 1, 2017

Can confirm this happens on 1.6 too.

@irbian
Copy link

irbian commented Jan 9, 2018

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
Copy link

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

Best Regards,
Giorgio

@deepakab03
Copy link

deepakab03 commented May 10, 2018

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
Copy link

erikyuzwa commented May 23, 2018

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
Copy link

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

@AlexanderEerenberg
Copy link

Same here =(

@eirslett
Copy link
Owner

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

@vacolane
Copy link

vacolane commented Aug 2, 2018

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
Copy link

@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
Copy link

@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
Copy link
Contributor

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

Theoderich added a commit to Theoderich/frontend-maven-plugin that referenced this issue Mar 12, 2019
… because File.rename does not support overwriting existing files on windows
Theoderich added a commit to Theoderich/frontend-maven-plugin that referenced this issue Mar 12, 2019
… because File.rename does not support overwriting existing files on windows
eirslett added a commit that referenced this issue Mar 12, 2019
Fix #670: Use Files.move instead of File.rename to move files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.