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?]: @yarnpkg/[email protected] produces bundles which yarn cannot consume #5637

Closed
1 task
adrian-gierakowski opened this issue Aug 3, 2023 · 5 comments · Fixed by #6356
Closed
1 task
Labels
bug Something isn't working

Comments

@adrian-gierakowski
Copy link

Self-service

  • I'd be willing to implement a fix

Describe the bug

due to recent esbuild target change from node14 to node18 builder build plugin produces bundles which lead to following errors:

Usage Error: This plugin cannot access the package referenced via node:fs which is neither a builtin, nor an exposed entry (when initializing @yarnpkg/plugin-helloworld, defined in <environment>)

To reproduce

yarn builder new plugin test-plugin
cd test-plugin
# Edit sources/index.js to import some node builtin using `node:` protocl
yarn build
YARN_PLUGINS=bundles/@yarnpkg/plugin-helloworld.js yarn hello world

Environment

System:
    OS: Linux 6.3 NixOS 23.05 (Stoat) 23.05 (Stoat)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
  Binaries:
    Node: 18.14.2 - /tmp/xfs-6ed5b272/node
    Yarn: 4.0.0-rc.48 - /tmp/xfs-6ed5b272/yarn
    npm: 9.5.0 - /nix/store/dnhhyhfql3cs9jmrhd3a05620higxy0i-nodejs-18.14.2/bin/npm

Additional context

No response

@adrian-gierakowski adrian-gierakowski added the bug Something isn't working label Aug 3, 2023
@adrian-gierakowski
Copy link
Author

applying a patch to @yarnpkg/builder based on this comment fixes it

adrian-gierakowski added a commit to rhinofi/yarnpnp2nix that referenced this issue Aug 3, 2023
1. checksum version 9 => 10 (so we neeed to remove 3 chars when creating nix hash)
  NOTE: this should really be done based on cacheKey from yarn.lock
2. patch @yarnpkg/builder (see: yarnpkg/berry#5637)
3. update execa and typescript
adrian-gierakowski added a commit to rhinofi/yarnpnp2nix that referenced this issue Aug 3, 2023
1. fix has extraction from checksum (using code lifted from berry)
2. patch @yarnpkg/builder (see: yarnpkg/berry#5637)
3. update execa and typescript
rgischk pushed a commit to encoway/yarn-scripts-cache that referenced this issue Nov 2, 2023
This branch does not yet work, I assume because there is a bug in @yarnpkg/builder. See these issues for details:
* yarnpkg/berry#5417
* yarnpkg/berry#5637
@adrian-gierakowski
Copy link
Author

this appears to be fixed using @yarnpkg/builder@npm:4.0.0 and yarn 4.0.2

@adrian-gierakowski
Copy link
Author

it turns out this is still a problem, it's just that it doesn't manifest with the example plugin

@adrian-gierakowski
Copy link
Author

the error can be reproduced by adding the following lines to the example plugin's source:

import p from 'node:process'

console.log(p.argv)

@adrian-gierakowski
Copy link
Author

applying a patch to @yarnpkg/builder based on this comment fixes it

this fix no longer works, however the patch from does: #5997

github-merge-queue bot pushed a commit that referenced this issue Aug 25, 2024
## What's the problem this PR addresses?

<!-- Describe the rationale of your PR. -->
<!-- Link all issues that it closes. (Closes/Resolves #xxxx.) -->

Yarn plugins used to be forbidden to import/require built-in modules
prefixed with `node:`.
see #6135
see #5417
Fixes #5637

The yarn plugin builder should be aware of this fact and produce bundled
code, that does not contain any `node:` prefixed import/require.

This is especially important when building plugins with 3rd party
dependencies, where the plugin author cannot "fix" the imports to yarn's
needs.

## How did you fix it?

<!-- A detailed description of your implementation. -->

I enabled the plugin-compiler to generate the plugin-code as needed:

I utilized the capability of `esbuild` to strip these `node:` prefixes
from import/require instructions.
Therefore, I added config options to the plugin build process to
instruct `esbuild` to do so.

This is a fix of the plugin builder, which enables plugin authors to
compile their work in a backwards-compatible way, so that the build
result is runnable in old/unpatched versions of yarn. Unpatched
regarding #5997

## Related

The #5997 tries to address the issue from the plugin-runtime side.
This would enable "broken" plugins to be runnable in all future/patched
versions of yarn-core.

## Additionally

This very PR aims to enable plugin authors to create plugins that are
runnable with unpatched versions of yarn-core.
It is considered a friction-free backwards-compatible solution on all
ends. Yet it does not replace #5997.


## Checklist

<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.

---------

Signed-off-by: Jan Kowalleck <[email protected]>
Co-authored-by: Maël Nison <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant