question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with node_modules in yarn 2 workspaces: Cannot find plugin 'x'

See original GitHub issue

Describe the issue When working with yarn 2 workspaces, node_modules are not located in the workspace-folder but in the root of the project.

architect throws an error when building:

- Cannot find plugin 'architect/plugin-remix'! Are you sure you have installed or created it correctly?
Error: Plugin error:
- Cannot find plugin 'architect/plugin-remix'! Are you sure you have installed or created it correctly?
    at format (/src/converter/node_modules/@architect/inventory/src/lib/error-fmt.js:15:13)

I traced the error back to @architect/inventory to the plugins-section: https://github.com/architect/inventory/blob/848958571ccad74753ee336dc47364f1298287dc/src/config/pragmas/plugins.js#L103

There it checks via cwd where the plugin may be. Maybe there is a way to adjust the cwd for this process?

Steps to reproduce

  • Create a project where you would use yarn 2
  • Add workspaces to the package.json root: workspaces: [ "app/*" ]
  • Add a workspace where architect lives in app/package.json
  • Install architect and a plugin
  • Start the app

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
HosseinAghacommented, Oct 29, 2022

Hi @ryanblock,
Thanks for the fast response.
These are the steps:

  1. first I created a yarn v3 monorepo using this guide (https://yarnpkg.com/getting-started/install)
  2. then I initiated a new remix-run project using yarn dlx create-remix@latest
  3. In the CLI wizard chose Just the basics and Architect
  4. Then add the remix directory to yarn workspaces in the root package.json
  5. And finally call yarn install anywhere in the repository
  6. Now you have a yarn 3 project that uses plug-and-play for dependency resolution
  7. First If you run yarn build in the remix project you’ll get many dependency error
  8. These are because of the architect package relying on phantom dependencies (packages that you require but are not in your package.json). Here is my .yarnrc.yml that resolves these mistakes (it is better to resolve them in the packages but unfortunately I don’t have free time for a PR right now)
  "@architect/architect@*":
    dependencies:
      "@architect/inventory": "*"
      "@architect/utils": "*"
  "@architect/utils@*":
    dependencies:
      "aws-sdk": "*"
  "@architect/deploy@*":
    dependencies:
      "aws-sdk": "*"
  "@architect/asap@*":
    dependencies:
      "aws-sdk": "*"
  "@architect/env@*":
    dependencies:
      "minimist": 1.2.6
  1. Finally after doing this you’ll be able to build the project but when your run yarn dev which using arc sandbox internally you encounter many errors like (cannot find module X in node_modules)

So to conclude architect packages have 2 issues that both are not standard Node.js practice and cause modern package managers to break or throw warnings:

  1. you’ve required packages without directly adding them to the package that requires them (phantom dependencies), check yarn pnp docs.
  2. you’ve required packages by providing their address in the node_modules instead of relying on the runtime to resolve them

Finally, I’m not sure that using yarn pnp or pnpm is a good idea in AWS lambda (definitely possible) but I know that users will definitely use them for their local development.

2reactions
HosseinAghacommented, Jul 30, 2022

I had the similar issue using the remix architect template.
Many developers use yarn v2 pnp for package management and I think this is one of architect’s most significant shortcomings in terms of DevX, especially for Remix developers.
Custom module resolution logic always leads to unexpected behavior for your users. IMHO, simply using require.resolve for requiring packages is much better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

yarn: cannot find module - typescript - Stack Overflow
This error is coming from the linter; I think it's checking inside the package lock file (which does not exist as yarn is...
Read more >
Plug'n'Play | Yarn - Package Manager
An overview of Plug'n'Play, a powerful and innovative installation strategy for Node.
Read more >
Advanced package manager features for npm, Yarn, and pnpm
The problem with the traditional node_modules approach; Yarn Berry's ... You have to specify missing dependencies in the package.json ...
Read more >
Support yarn workspaces (better indexing of node_modules ...
If you encounter problems with import resolving, make sure that your yarn version is up to date 3.2.2 had a bug where the...
Read more >
Building a Monorepo with Yarn 2 - Heroku Blog
Yarn 2 is officially supported by Heroku. Here's a popular use case for Yarn enhanced by Yarn 2: using workspaces to manage dependencies...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found