clean-webpack-plugin: Error: "project root is outside of project"

Hi,

Due to various reasons in our project, the client builds into the ‘public’ folder of our rails app. For illustration purposes:

  • server/client - client dir (where webpack.config.js lives), and where the build is run from
  • server/public - webpack config.output.path dir, where webpack builds relative to

It looks like this plugin relies on workingDir (i.e. process.cwd()) over webpack’s config.output.path.

Would it be ok to change this? Webpack is building happily into a folder that isn’t the cwd.

What I’m looking for is to remove / clean the files pre-build, in:

  • server/public/scripts and server/public/styles
  • leave anything else in server/public intact

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

@alextreppass You do not need to change anything. process.cwd() is the safe default for the root option.

Where projectRootDir is set: https://github.com/johnagan/clean-webpack-plugin/blob/master/index.js#L41

var CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
  plugins: [
    new CleanWebpackPlugin(['dist', 'build'], {
      root: '/full/project/path/server/public',
      verbose: true, 
      dry: false
    })
  ]
}

Does not for work projects with multiple workspaces, where there is some webpack.config.base.js injecting clean-webpack-plugin in it located in another folder outside the subpackage. E.g.: =packages ==shared ===webpack.config.base.js ==subpackage1 ===webpack.config.js