frontend-maven-plugin icon indicating copy to clipboard operation
frontend-maven-plugin copied to clipboard

Error deleting file because in use by another process

Open peterkronenberg opened this issue 4 years ago • 6 comments

When I run a build, I sometimes get this error: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.12.0:install-node-and-npm (install node and npm) on project demoIntegrate: Could not install Node: Unable to delete file: c:\project\target\node\tmp\node-v14.18.0-win-x64: c:\project\target\node\tmp\node-v14.18.0-win-x64\node_modules\npm\node_modules\iconv-lite\encodings: The process cannot access the file because it is being used by another process

The error is not always with the same file, although always something in the tmp directory

The error frequently happens after I just did a successful build. There is definitely no other process using this file. Sometimes, I can manually delete the target folder and then I can run it successfully.

What's even weirder is that it looks like it deletes the target directory (since I'm doing a mvn clean install)

[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demoIntegrate --- [INFO] Deleting c:\project\target [INFO] [INFO] --- frontend-maven-plugin:1.12.0:install-node-and-npm (install node and npm) @ demoIntegrate --- [INFO] Installing node version v14.18.0 [INFO] Unpacking C:\Users\Peter\.m2\repository\com\github\eirslett\node\14.18.0\node-14.18.0-win-x64.zip into c:\project\target\node\tmp [INFO] Copying node binary from c:\project\target\node\tmp\node-v14.18.0-win-x64\node.exe to c:\project\target\node\node.exe

peterkronenberg avatar Oct 12 '21 00:10 peterkronenberg

Try not putting node inside the target directory. (I guess you tried to configure that as installDirectory?)

eirslett avatar Oct 12 '21 10:10 eirslett

Yes, I was following some instructions to get React integrated with SpringBoot. Other than this problem, it works fine. Do you have any other suggestions for how to get Springboot to be able to serve the React files? I want the React Build files in the target directory, not necessarily the Node install

peterkronenberg avatar Oct 12 '21 12:10 peterkronenberg

What my process is doing is running frontend-maven-plugin first, and then it uses maven-resources-plugin to copy files from the frontend build directory into the target directory (so that Spring can serve them). So there's no reason to build node in the target directory. So I changed to to creating node in the frontend-src-dir.

<configuration>
        <nodeVersion>${node.version}</nodeVersion>
        <workingDirectory>${frontend-src-dir}</workingDirectory>
        <installDirectory>${frontend-src-dir}</installDirectory>
 </configuration>

But I get a similar problem. So it has nothing to do with being in the target directory. Where ever I put the node files, it seems to have problems deleting them later

Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.12.0:install-node-and-npm (install node and npm) on project demoIntegrate: Could not install Node: Unable to delete file: E:\project\src\main\frontend\node\tmp\node-v14.18.0-win-x64: E:\project\src\main\frontend\node\tmp\node-v14.18.0-win-x64\node_modules\npm\node_modules: The process cannot access the file because it is being used by another process -> [Help 1]

peterkronenberg avatar Oct 12 '21 14:10 peterkronenberg

Then I have no idea what it can be... 🤷 I have never seen that error myself, and I also don't have access to a Windows computer. So let's hope somebody finds out!

Hm, maybe it's some kind of antivirus running on your computer, that tries to scan the downloaded tmp file? Could that be the "competing" process?

eirslett avatar Oct 12 '21 21:10 eirslett

I'm pretty sure it's not that, although I can't prove it. Do you by any chance have any references to other documentation which shows the best way to integrate React with SpringBoot using the plugin? The best one I've found is https://dev.to/arpan_banerjee7/run-react-frontend-and-springboot-backend-on-the-same-port-and-package-them-as-a-single-artifact-14pa, but would love to get other ideas

peterkronenberg avatar Oct 12 '21 21:10 peterkronenberg

Try disabling the antivirus then! (Look at all antivirus-like processes running on the computer, and kill them)

For Spring Boot + React, you could try something like JHipster, which is more full-blown. https://www.jhipster.tech/

eirslett avatar Oct 12 '21 21:10 eirslett