vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

TypeError: Cannot destructure property `withFileTypes` of 'undefined' or 'null' with Yarn PnP on second build #6954

Open nickbreen opened 2 years ago

nickbreen commented 2 years ago

Version

4.5.15

Reproduction link

github.com

Environment info


  System:
    OS: Linux 5.15 Fedora 34 (Workstation Edition) 34 (Workstation Edition)
    CPU: (28) x64 Intel(R) Xeon(R) CPU E5-2697 v3 @ 2.60GHz
  Binaries:
    Node: 10.22.1 - /tmp/xfs-c2b4c986/node
    Yarn: 2.4.3 - /tmp/xfs-c2b4c986/yarn
    npm: 6.14.6 - ~/src/lmax/buck-all/opt/node/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: 45.2.0
  npmGlobalPackages:
    @vue/cli: Not Found

Note: @vue/cli is installed in the same project.

Steps to reproduce

Clone repo. Install yarn classic Install node v10.22.1 Run:

yarn install
yarn build  # this succeeds
yarn build  # again, this fails
yarn build --no-clean  # this should succeed
yarn build --no-clean  # again, this should succeed
yarn build  # again, this fails
rm -rf dist
yarn build  # this succeeds
yarn build  # again, this fails
rm -rf dist
yarn build  # this succeeds

What is expected?

Successful build without having to specify --no-clean or delete the output directory manually.

Note that serve also fails with this same error and the above work-arounds do not work.

What is actually happening?

$ yarn build

✔ Building for production... ERROR TypeError: Cannot destructure property withFileTypes of 'undefined' or 'null'. TypeError: Cannot destructure property withFileTypes of 'undefined' or 'null'. at PosixFS.readdirPromise (/home/breenn/src/vue-cli-node-yarn-pnp-bug/.pnp.js:19178:23) at process.nextTick (/home/breenn/src/vue-cli-node-yarn-pnp-bug/.pnp.js:22205:20) at process._tickCallback (internal/process/next_tick.js:61:11)


This is triggering a bug in yarn but only on the second build - which means there is something that the vue cli is doing differently the second time (and the first time with serve), something to do with the cleaning the output directory.

nickbreen commented 2 years ago

Error from serve

 ERROR  Failed to compile with 1 error                                                                                                  5:30:40 PM

 error  

Cannot destructure property `withFileTypes` of 'undefined' or 'null'.

 @ ./.yarn/$$virtual/webpack-dev-server-virtual-31a67a73dd/0/cache/webpack-dev-server-npm-3.11.3-ba74f2e2c6-dfc70a0d96.zip/node_modules/webpack-dev-server/client?http://192.168.178.33:8081&sockPath=/sockjs-node 76:17-67
 @ multi ./.yarn/$$virtual/webpack-dev-server-virtual-31a67a73dd/0/cache/webpack-dev-server-npm-3.11.3-ba74f2e2c6-dfc70a0d96.zip/node_modules/webpack-dev-server/client?http://192.168.178.33:8081&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
nickbreen commented 2 years ago

The work-around is to use YARN_NODE_LINKER=node-modules which disables the PnP system and avoids the yarn bug.