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

Monorepo with Yarn PnP in the root and standalone project with esbuild in a subdir #2495

Closed
JanVoracek opened this issue Aug 24, 2022 · 5 comments

Comments

@JanVoracek
Copy link

We have a repository with the following structure:

.
├── .pnp.cjs
├── package.json // { "workspaces": ["packages/*"] } - notice that `prototypes` are not part of the workspaces
├── packages
│   ├── package-a/
│   ├── package-b/
│   └── ...
└── prototypes
    ├── esbuild-prototype // uses npm
    │   ├── package.json
    │   └── package-lock.json
    ├── some-other-prototype // can use pnpm, yarn + node_modules linker, etc.
    └── ...

In this case, the esbuild bundler doesn't work correctly because it finds the .pnp.cjs file in the repository root and tries to resolve dependencies using the PnP strategy - even though the esbuild project is not part of the Yarn workspaces and doesn't even use Yarn at all.

@merceyz
Copy link

merceyz commented Aug 25, 2022

This is working as intended, if you want a directory to not be part of the project you need to tell Yarn about it using pnpIgnorePatterns.

pnpIgnorePatterns:
    - "./prototypes/**"

@evanw
Copy link
Owner

evanw commented Aug 29, 2022

Closing because it sounds like this is working as intended, and there is an easy workaround available.

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Aug 29, 2022
@JanVoracek
Copy link
Author

I'm not sure it works as intended. Here's a demo repository that reproduces the problem: https://github.com/JanVoracek/esbuild-yarn-demo. There is also a GH Action demonstrating the failure: https://github.com/JanVoracek/esbuild-yarn-demo/actions/runs/2998205785

Also, it seems that Yarn can resolve the import but esbuild crashes on Could not resolve "react" anyway:

$ echo "[\"react\", \"$PWD/prototypes/esbuild-prototype/src/app.tsx\"]" | node .pnp.cjs
[null,".../prototypes/esbuild-prototype/node_modules/react/index.js"]

@evanw
Copy link
Owner

evanw commented Sep 10, 2022

Thank you for providing a way to reproduce this. It looks like the problem is that Yarn's regular expression for ignorePatternData uses regular expression features that work in JavaScript but not in Go. Specifically this is not a valid Go regular expression:

(^(?:\.yarn\/sdks(?:\/(?!\.{1,2}(?:\/|$))(?:(?:(?!(?:^|\/)\.{1,2}(?:\/|$)).)*?)|$))$)|(^(?:prototypes(?:\/(?!\.{1,2}(?:\/|$))(?:(?:(?!(?:^|\/)\.{1,2}(?:\/|$)).)*?)|$))$)

I'm not sure what to do about this.

Edit: Pretty-printed:

(
  ^(
    ?:\.yarn\/sdks(
      ?:\/(
        ?!\.{1,2}(
          ?:\/|$
        )
      )(
        ?:(
          ?:(
            ?!(
              ?:^|\/
            )\.{1,2}(
              ?:\/|$
            )
          ).
        )*?
      )|$
    )
  )$
)|(
  ^(
    ?:prototypes(
      ?:\/(
        ?!\.{1,2}(
          ?:\/|$
        )
      )(
        ?:(
          ?:(
            ?!(
              ?:^|\/
            )\.{1,2}(
              ?:\/|$
            )
          ).
        )*?
      )|$
    )
  )$
)

The problematic part is the use of (?! which Go doesn't support.

@evanw evanw reopened this Sep 10, 2022
@evanw
Copy link
Owner

evanw commented Sep 10, 2022

Perhaps I can just manually strip (?!\.{1,2}(?:\/|$)) and (?!(?:^|\/)\.{1,2}(?:\/|$)) from this regular expression. They seem to be used by Yarn to guard against the . and .. path segments in the middle of a relative URL. But esbuild will never generate such path segments, so I don't think these cases will ever be hit? In any case, stripping these means these regular expression has a better chance of working which is better than what's happening now. Stripping these fixes this issue, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants