Rollup plugin delete issue
Reproduction repository showcasing issue with rollup-plugin-delete with nested target in yarn2 PnP
When target
to be removed contains nested folder AND if the repository is utilizing Yarn2 and Plug'n'Play the build fails
Steps to reproduce:
- Clone repo via
gh repo clone v1adko/pnp-rollup-delete-issue && cd pnp-rollup-delete-issue
- Install depenencies via
yarn
cd packages/rollup
yarn build
The build will fail with the following error:
[!] (plugin delete) TypeError: Cannot destructure property 'withFileTypes' of '(intermediate value)(intermediate value)(intermediate value)' as it is null.
TypeError: Cannot destructure property 'withFileTypes' of '(intermediate value)(intermediate value)(intermediate value)' as it is null.
at PosixFS.readdirPromise
...
- Go to rollup.config.js and edit the
targets
todist1/*
(does not contain nested folder) - Rerun
yarn build
- script successfully executes and the contents of the folder are deleted
Solution
In the targets
config option specify an array as follows: ["dist2/**/*", "dist2/*"]
(order matters)
Alternative solution
Ditch the plugin and for build script do rimraf ./dist && rollup -c
Alternative solution 2 -> downgrade to v1.2.0
yarn add -D rollup-plugin-delete@1.2.0
To verify that script works as-is in regular node_modules linker:
git co node-modules-working
yarn
yarn build