Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: readdir implementations don't accept null as second argument #3234

Closed
1 task done
paul-soporan opened this issue Aug 6, 2021 · 9 comments · Fixed by #3239
Closed
1 task done

[Bug]: readdir implementations don't accept null as second argument #3234

paul-soporan opened this issue Aug 6, 2021 · 9 comments · Fixed by #3239
Labels
bug Something isn't working reproducible This issue can be successfully reproduced

Comments

@paul-soporan
Copy link
Member

Self-service

  • I'd be willing to implement a fix

Describe the bug

The readdir implementations in @yarnpkg/fslib don't accept null as the second argument (which is supported by Node) and throw a cryptic:

TypeError: Cannot destructure property 'withFileTypes' of '(intermediate value)(intermediate value)(intermediate value)' as it is null.

To reproduce

await packageJsonAndInstall({});

await expect(
  yarn(`node`, `-e`, `require('fs').readdirSync('.', null)`)
).resolves.toBeTruthy();

Environment

System:
    OS: Linux 5.13 Arch Linux
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
  Binaries:
    Node: 16.0.0 - /tmp/xfs-62396191/node
    Yarn: 3.0.1-rc.1.dev - /tmp/xfs-62396191/yarn
    npm: 7.10.0 - ~/.nvm/versions/node/v16.0.0/bin/npm

Additional context

There are likely other methods inside @yarnpkg/fslib that should accept null but don't.

@paul-soporan paul-soporan added the bug Something isn't working label Aug 6, 2021
@yarnbot yarnbot added the reproducible This issue can be successfully reproduced label Aug 6, 2021
@yarnbot
Copy link
Collaborator

yarnbot commented Aug 6, 2021

This issue reproduces on master:

Error: expect(received).resolves.toBeTruthy()

Received promise rejected instead of resolved
Rejected to value: [Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js node -e require('fs').readdirSync('.', null)
/tmp/tmp-17dHP2PZy1YrER/.pnp.cjs:5952
    withFileTypes
    ^

TypeError: Cannot destructure property 'withFileTypes' of '(intermediate value)(intermediate value)(intermediate value)' as it is null.
    at URLFS.readdirSync (/tmp/tmp-17dHP2PZy1YrER/.pnp.cjs:5952:5)
    at [eval]:1:15
    at Script.runInThisContext (vm.js:134:12)
    at Object.runInThisContext (vm.js:310:38)
    at internal/process/execution.js:81:19
    at [eval]-wrapper:6:22
    at evalScript (internal/process/execution.js:80:60)
    at internal/main/eval_string.js:27:3

]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-0c0da74930.zip/node_modules/expect/build/index.js:138:15)
    at module.exports (evalmachine.<anonymous>:4:7)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)

@adam-nygate
Copy link

Thanks for this - I've just run in to this issue. Out of curiosity, do you know when this will be published as a new version of yarn?

@merceyz
Copy link
Member

merceyz commented Aug 10, 2021

I just triggered a release (https://github.com/yarnpkg/berry/actions/runs/1116604206) so it should be ready in about 15 minutes, then you can run the following command to get the fix

yarn set version berry && yarn set version canary

@rtritto
Copy link

rtritto commented Aug 10, 2021

@merceyz the upload of release is failed...

@merceyz
Copy link
Member

merceyz commented Aug 10, 2021

That's a known issue with the publish to the registry, the release itself was successful so the command in #3234 (comment) is still the solution

@rtritto
Copy link

rtritto commented Aug 10, 2021

Thanks
yarn version with this fix is 3.0.1-rc.2.
I solved with yarn set version canary && yarn command to recreate .pnp.cjs file.

@ebrooks42
Copy link

I had the same error with my personal website this afternoon when migrating to yarn berry (w/ zero installs & plug & play). Specifically, the app had a Github Action which was executing a yarn exec cdk deploy step (to deploy to AWS). On execution, the step would throw the aforementioned exception:
TypeError: Cannot destructure property 'withFileTypes'

I was able to fix the issue the same way as @rtritto. After setting yarn version to canary and rerunning yarn, several files were updated. I committed and pushed the changes, and thanks to zero installs, the changes worked exactly the same in the Github Action as locally.

Thanks for this issue! Really saved me some time.

@dmattia
Copy link
Contributor

dmattia commented Jan 14, 2022

For anyone coming up on this in the future, I fixed this by upgrading from yarn v3.0.0 by running yarn set version 3.0.1 which is the first non-release-candidate version to have this fix

@nickbreen
Copy link

Any chance this could be back-ported to 2.4.x for those of us stuck on Node v10?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible This issue can be successfully reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants