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

Lerna, Yarn & Workspaces path resolution wrong for preact / prerender.js #1043

Closed
tomsiwik opened this issue Mar 10, 2020 · 5 comments · Fixed by #1418
Closed

Lerna, Yarn & Workspaces path resolution wrong for preact / prerender.js #1043

tomsiwik opened this issue Mar 10, 2020 · 5 comments · Fixed by #1418

Comments

@tomsiwik
Copy link

tomsiwik commented Mar 10, 2020

Do you want to request a feature or report a bug?
bug

What is the current behaviour?
Because of #803, which was a fix for #795 mono-repo configurations no longer resolves preact correctly and returns:

✖ ERROR Template execution failed: Error: Cannot find module './node_modules/preact'

This is happening when using lerna, yarn and a workspaces configuration.

If the current behaviour is a bug, please provide the steps to reproduce.

Please use the following global packages and pkgmgr to reproduce:

  • yarn
  • preact-cli
  • lerna

Easy shell script:
https://gist.github.com/tomsiwik/901c1acb122c9bb18d513bb348b201ea

What is the expected behaviour?

preact and preact-render-to-string should use common node_modules path either with require('preact') or relative to the module beeing used ${__dirname}/../../../../preact (fragile).
One other solution is regexing for __dirname: const moduleRoot = __dirname.match(/.+(?<=.*node_modules)/gm)[0]

If this is a feature request, what is motivation or use case for changing the behaviour?

Workspaced lerna breaks now what used to work pre-fix.
See change: https://github.com/preactjs/preact-cli/pull/803/files#diff-dc9a93cd49896d6e2f0463ca332bf943L28

Please mention other relevant information.

Please paste the results of preact info here.
preact-cli 2.2.1

@tomsiwik tomsiwik changed the title Lerna, Yarn & Workspaces path resolution blocken for preact / prerender.js Lerna, Yarn & Workspaces path resolution wrong for preact / prerender.js Mar 10, 2020
@617dev
Copy link

617dev commented Jun 23, 2020

I just moved a preact app into my lerna monorepo that's using yarn workspaces and I'm encountering the same exact issue. Is there any workaround or progress on this?

@keithm27
Copy link

Running into the same issue as this when using preact-cli inside a mono-repo. Is there any progress on this issue?

@tomsiwik
Copy link
Author

The only workaround for me was disabling yarn workspaces for lerna.

@nmquebb
Copy link

nmquebb commented Sep 15, 2020

Not ideal, but after install I just copy preact and preact-render-to-string to the packages node_modules. I run a top level prepare command (I actually use ultra-runner) which each package handles in their own specific package.json.

If you have everything in ./packages it'd be something like:

...
"scripts": {
    "prepare": "cp -R ../node_modules/preact ./node_modules && cp -R ../node_modules/preact-render-to-string ./node_modules",
}
...

@JohnnyCrazy
Copy link

Small workaround for now, add two packages to your nohoist list in your root package.json:

"workspaces": {
  "packages": ["packages/*"],
  "nohoist": ["**/preact", "**/preact-render-to-string"]
},

But for the long run, a correct package resolution should be the way to go :)

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

Successfully merging a pull request may close this issue.

5 participants