FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

[BUG] Snowpack can't build (resolve) dependencies across multiple workspaces #2910

Open tajo opened 3 years ago

tajo commented 3 years ago

Bug Report Quick Checklist

Describe the bug

Snowpack can't resolve dependencies from multiple yarn workspaces at the same time. Imagine this scenario with two workspaces one and two:

/project
 - package.json
 - /one
   - package.json
 - /two 
   - package.json

The workspace one imports snowpack and some other dependencies (react, styled-components, debug...) to build the main web application (for example a storybook like project).

The workspace two has stories / components that import some additional dependencies.

The issue is I can't make snowpack to correctly mount both one and two source folder and their dependencies. I can set root to workspace one but then it can't resolve deps in two and vice versa.

The errors says something like this:

Error: Package "foo" not found. Have you installed it?

To Reproduce

Minimal repro.

git clone git@github.com:tajo/snowpack-berry.git
cd snowpack-berry
yarn install
cd two
yarn dev

getting this error

snowpack

▼ Console

[snowpack] ! building dependencies...
[snowpack] (node:41367) UnhandledPromiseRejectionWarning: Error: Package "canvas-confetti" not found. Have you installed it? 
    at Object.resolveEntrypoint (/Users/vojtech/Projects/snowpack-berry/.yarn/cache/snowpack-npm-3.0.13-04dbc965f7-5ed74e2fb0.zip/node_modules/snowpack/lib/index.js:48676:15)
    at resolveWebDependency (/Users/vojtech/Projects/snowpack-berry/.yarn/cache/snowpack-npm-3.0.13-04dbc965f7-5ed74e2fb0.zip/node_modules/snowpack/lib/index.js:48983:29)
    at Object.install (/Users/vojtech/Projects/snowpack-berry/.yarn/cache/snowpack-npm-3.0.13-04dbc965f7-5ed74e2fb0.zip/node_modules/snowpack/lib/index.js:49094:36)
    at Object.run (/Users/vojtech/Projects/snowpack-berry/.yarn/cache/snowpack-npm-3.0.13-04dbc965f7-5ed74e2fb0.zip/node_modules/snowpack/lib/index.js:49313:37)
    at installDependencies (/Users/vojtech/Projects/snowpack-berry/.yarn/cache/snowpack-npm-3.0.13-04dbc965f7-5ed74e2fb0.zip/node_modules/snowpack/lib/index.js:50824:46)
    at async Object.prepare (/Users/vojtech/Projects/snowpack-berry/.yarn/cache/snowpack-npm-3.0.13-04dbc965f7-5ed74e2fb0.zip/node_modules/snowpack/lib/index.js:50879:35)
    at async startServer (/Users/vojte

You can change ./one/run.js root to __dirname and get this error instead

...
Package "emojisplosion" not found. Have you installed it?
...

Expected behavior

I tried multiple other root and workspaceRoot settings but nothing seems to be working? Is there some way to be able mount folder across workspaces?

tajo commented 3 years ago

I guess what's happening is resolveDependencyManifest and underlying resolve need to set correct baseDir (which is root in our case and you can pick only one root). The fix could be being able to set mount specific roots?

Offirmo commented 3 years ago

Weighing on this issue, also using multiple workspaces (yarn) in the same monorepo.

crobinson42 commented 3 years ago

@tajo I don't think the solution is to have multiple roots but rather a relative resolution. Here's an example: Package A & B are in a mono-repo and both use a different version of a dependency. If Package A imports Package B which uses a different version of a dependency that snowpack finds first in Package A's root, there can/will be conflicts and issues.

stavalfi commented 3 years ago

So it means snowpack does not support yarn2 (berry) with monorepo. =\