elwin013/parcel-plugin-static-files-copy

Tries to make the directory again on a subsequent run and fails

Closed this issue · 8 comments

Hi,

I am using version 2.4.1 of this module to copy static assets into the parcel build directory. If parcel is running as watch, or if I manually do a subsequent build run without first clearing the previous files it fails with the following message:

....
(node:63300) UnhandledPromiseRejectionWarning: Error: EEXIST: file already exists, mkdir 'C:\project\wwwroot\images'
at Object.fs.mkdirSync (fs.js:905:18)
at processStaticFiles (C:\project\node_modules\parcel-plugin-static-files-copy\index.js:157:20)
at Bundler.bundler.on (C:\project\node_modules\parcel-plugin-static-files-copy\index.js:167:13)
at
(node:63300) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:63300) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I would expect it to just copy the files again into the directory even if it already exists. Would you agree with this? Hope this helps in resolving this one if you do.

Thanks and regards,
Andrew

@retroburst Hey! Thanks for reporting this! Could you paste here configuration you use? :-)

@elwin013 Hey, sure thing, please find my package.json below. If there is anything else you need, please let me know. Thanks for your work on this plugin!
Cheers,
Andrew

{
  "name": "...",
  "version": "1.0.0",
  "description": "...",
  "main": "index.js",
  "scripts": {
    "lint": "eslint assets/js",
    "watch": "parcel watch assets/js/app.js --out-dir wwwroot/ --out-file app.dist.js --log-level 4  --target browser --no-hmr",
    "build": "parcel build assets/js/app.js --out-dir wwwroot/ --out-file app.dist.js --log-level 4  --target browser --detailed-report"
  },
  "author": "...",
  "license": "UNLICENSED",
  "dependencies": {
    "@analytics/google-analytics": "^0.4.0",
    "alertify": "^0.3.0",
    "analytics": "^0.5.1",
    "bootstrap": "^4.5.0",
    "check-types": "^11.1.2",
    "datatables": "^1.10.18",
    "jquery": "^3.5.1",
    "lodash": "^4.17.15",
    "loglevel": "^1.6.8",
    "moment": "^2.26.0",
    "popper.js": "^1.16.1",
    "regenerator-runtime": "^0.13.5",
    "vee-validate": "^3.3.2",
    "vue": "^2.6.11"
  },
  "devDependencies": {
    "@vue/component-compiler-utils": "^3.1.2",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.8.0",
    "parcel-bundler": "^1.12.4",
    "parcel-plugin-static-files-copy": "^2.4.1",
    "sass": "^1.26.7",
    "vue-template-compiler": "^2.6.11"
  },
  "alias": {
    "vue": "./node_modules/vue/dist/vue.common.js"
  },
  "staticFiles": {
    "staticPath": [
      {
        "staticPath": "assets/images",
        "staticOutDir": "./images"
      }
    ]
  }
}

@retroburst, @jindev - can you test with 2.4.2 version if problem persists (version already in npm)?

@elwin013 - thanks for the update and new version. I've tried using 2.4.2 and it gets further this time, though unfortunately it still seems to trip up on a sub-directory that already exists. In the output below, you can see it doesn't try to create the target directory anymore and copies over the existing favicon.png, which is perfect. However, when it gets to a sub-directory within the target, it seems to try and create it and throws an error.

Static file 'C:\project\assets\images\favicon.png' already exists in 'C:\project\wwwroot\images'. Overwriting.
(node:148748) UnhandledPromiseRejectionWarning: Error: EEXIST: file already exists, mkdir 'C:\project\wwwroot\images\home'

We're very close, hope this helps clear this one.

Thanks!

@retroburst I've published 2.4.3 version to NPM, could you test if it solves problem? Sorry for asking it again, but I cannot reproduce bug - on my machine everything works as expected..

@elwin013 - Thank you very much! All working perfectly now! I wonder if it was to do with OS differences? - I have to use Windows 10 at work (😭)

@retroburst Glad that it worked! :-)

All (probably) because mkdir behaves differently when using "recursive" option in node. In case of Linux (I have GNU Coreutils locally) it uses -p option which works like this no error if existing, make parent directories as needed. For Windows (and as seen in #50 for macOS too) there is different implementation of this and it throw error if directory exists.

Thanks for fixing this @elwin013, kind of frustrating that mkdir is behaving differently in node for different OS's.