Skip to content
This repository has been archived by the owner on Mar 23, 2018. It is now read-only.

Tries to cleanup / when run under webpack-dev-server #7

Closed
jonathanperret opened this issue Mar 8, 2016 · 4 comments
Closed

Tries to cleanup / when run under webpack-dev-server #7

jonathanperret opened this issue Mar 8, 2016 · 4 comments

Comments

@jonathanperret
Copy link
Contributor

Warning: try this in a VM/container/throwaway machine. There is a risk that files will be removed from all over the disk!

With the example webpack.config.js:

{
  output: {
    path: "/my/output/path"
  },
  plugins: [
    // Remove all the files from /my/output/path that are not generated by the
    // the current instance of the webpack compiler
    new WebpackCleanupPlugin()
  ]
}

If you try running webpack-dev-server:

$ npm install webpack-dev-server
$ ./node_modules/.bin/webpack-dev-server

You will end up with, if you're lucky, an error in recursiveReaddirSync:

Error: EBADF: bad file descriptor, lstat '/dev/fd/22'
    at Error (native)
    at Object.fs.lstatSync (fs.js:839:18)
    at …/node_modules/webpack-cleanup-plugin/node_modules/recursive-readdir-sync/index.js:12:16
    at Array.forEach (native)
    at recursiveReaddirSync (…/node_modules/webpack-cleanup-plugin/node_modules/recursive-readdir-sync/index.js:11:9)
    at …/node_modules/webpack-cleanup-plugin/node_modules/recursive-readdir-sync/index.js:14:26
    at Array.forEach (native)
    at recursiveReaddirSync (…/node_modules/webpack-cleanup-plugin/node_modules/recursive-readdir-sync/index.js:11:9)
    at /Users/Sebastien/code/boobsunit/boob_identity/node_modules/webpack-cleanup-plugin/node_modules/recursive-readdir-sync/index.js:14:26
    at Array.forEach (native) 

If you're unlucky, the scan will complete and WebpackCleanupPlugin will happily proceed with removing all the files from your disk.

This happens because webpack-dev-server forces the output path to /: https://github.com/webpack/webpack-dev-server/blob/5b94506/bin/webpack-dev-server.js#L142

Because webpack-dev-server uses an in-memory filesystem, it can get away with a / output path. Not so for WebpackCleanupPlugin, unfortunately.

@jonathanperret jonathanperret changed the title Tries to cleanup / when run under webpack-dev-server Tries to cleanup / when run under webpack-dev-server Mar 8, 2016
@jonathanperret
Copy link
Contributor Author

Note that at least one other plugin hit that issue: gajus/write-file-webpack-plugin#1

@gpbl
Copy link
Owner

gpbl commented Mar 8, 2016

Thanks for reporting. I never tested this plugin with the dev server. 😰

I think the best solution is explicitly requiring the path to delete from the constructor.

jonathanperret added a commit to jonathanperret/webpack-cleanup-plugin that referenced this issue Mar 8, 2016
In particular, `webpack-dev-server` forces an in-memory filesystem and
sets the output path to `/`, breaking this plugin. Fixes gpbl#7.
@kmcmichael-twist
Copy link

@gpbl Remove this repo and disable the npm package if you aren't going to fix this problem. You should have removed this in March until you addressed the issue.

@gpbl gpbl closed this as completed in #8 Aug 20, 2016
@gpbl
Copy link
Owner

gpbl commented Aug 20, 2016

Yup @kmcmichael-twist sorry for the unforgivable delay 🙏
Released as v0.3.0 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants