I am using grunt-contrib-copy to create a build/ folder for my NodeJS express application before deploying it. When running the command, it fails with the error that the folder already exists (Error code: EEXIST).
The copy block in the Gruntfile looks like this:
copy : {
build : {
options : {
mode : true
},
files : [
{
expand : true,
src : files_to_deploy,
dest : 'build/',
flatten : false,
filter : 'isFile'
},
],
},
},
The files_to_deploy is an array containing the files. In a shortened form, it looks like this:
const files_to_deploy = [
'app.js',
'package.json',
'controllers/**',
'models/**',
'routes/**',
'!**/*.test.js'
];
When I am calling grunt copy:build --verbose, I get the following output (shortened).
[...]
Running "copy:build" (copy) task
Verifying property copy.build exists in config...OK
Files: app.js -> build/app.js
Files: package.json -> build/package.json
[...]
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode
Copying app.js -> build/app.js
Reading app.js...OK
Writing build/app.js...Warning: Unable to create directory "build" (Error code: EEXIST). Use --force to continue.
Aborted due to warnings.
The thing is, grunt creates the build/ folder. And it even successfully copies the full app.js file into it. But it then simply stops.
I checked permissions and they look good. I tried to run it with sudo and it fails with the same message. I checked everything out into a fresh folder, same error. And I even have a very similar project with basically an identical structure and Gruntfile and everything works there.
Additional details:
- node version: 14.15.1
- grunt: 1.6.1
- grunt-contrib-copy: 1.0.0
- WSL 1
Any help, hints or points are highly appreciated!