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?]: Error codes for package exports in PnP don't match node builtin errors #3740

Closed
1 task
bgotink opened this issue Nov 17, 2021 · 3 comments · Fixed by #5331
Closed
1 task

[Bug?]: Error codes for package exports in PnP don't match node builtin errors #3740

bgotink opened this issue Nov 17, 2021 · 3 comments · Fixed by #5331
Assignees
Labels
bug Something isn't working reproducible This issue can be successfully reproduced

Comments

@bgotink
Copy link
Member

bgotink commented Nov 17, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

There are error codes linked to package exports in node.js, but these are absent when using PnP.
Those codes are useful when trying to figure out what is going wrong. Their absence also makes require and require.resolve harder to work with in tools that try to provide useful error messages to users.

The following codes are present within node, though the list is just a quick lookup in node's code so possibly not exhaustive:

  • ERR_INVALID_PACKAGE_CONFIG
  • ERR_INVALID_PACKAGE_TARGET
  • ERR_PACKAGE_IMPORT_NOT_DEFINED (for imports, which yarn doesn't support yet afaik)
  • ERR_PACKAGE_PATH_NOT_EXPORTED
  • ERR_UNSUPPORTED_DIR_IMPORT

To reproduce

await packageJsonAndInstall({
  dependencies: {
    uvu: `0.5.2`,
  }
});

await expect(node(`require.resolve('uvu/package.json')`)).resolves.toHaveProperty(
  `code`,
  `ERR_PACKAGE_PATH_NOT_EXPORTED`,
);

Environment

System:
    OS: macOS 11.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.17.6 - /private/var/folders/_d/ch2kc4h960d10cy_2c41qqzw0000gn/T/xfs-a1ff373c/node
    Yarn: 3.1.0 - /private/var/folders/_d/ch2kc4h960d10cy_2c41qqzw0000gn/T/xfs-a1ff373c/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm

Additional context

No response

@bgotink bgotink added the bug Something isn't working label Nov 17, 2021
@yarnbot yarnbot added the reproducible This issue can be successfully reproduced label Nov 17, 2021
@yarnbot
Copy link
Collaborator

yarnbot commented Nov 17, 2021

This issue reproduces on master:

Error: expect(received).resolves.toHaveProperty(path, value)

Expected path: "code"
Received path: []

Expected value: "ERR_PACKAGE_PATH_NOT_EXPORTED"
Received value: {}
    at Object.toHaveProperty (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-0c0da74930.zip/node_modules/expect/build/index.js:202:20)
    at module.exports (evalmachine.<anonymous>:8:68)
    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)

@merceyz
Copy link
Member

merceyz commented Nov 17, 2021

For exports validation we're waiting on lukeed/resolve.exports#3, ref the TODO list in #2431

@bgotink
Copy link
Member Author

bgotink commented Nov 17, 2021

I see… This isn't purely about the validation (though that's certainly linked) but the fact that require.resolve in PnP can now throw errors that don't have a code, which is unexpected.
I think the errors it explicitly throws would have code ERR_PACKAGE_PATH_NOT_EXPORTED in node itself, though implicit errors (e.g. if exports is an array) can also pop up and those would require another code.

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.

3 participants