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.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:5

github_iconTop GitHub Comments

4reactions
JohnnyCrazycommented, Oct 2, 2020

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 😃

0reactions
kidquebcommented, 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",
}
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix React Issues in Lerna using Yarn Workspaces
Finally, set the “private” key to true because the repository should be private if yarn workspaces is to work.
Read more >
Managing Monorepo using Lerna and Yarn workspaces
This article shows how to manage multiple packages in a single repository. What is Monorepo? In this article, what we call "Monorepo" is...
Read more >
Monorepo Javascript Projects with Yarn Workspaces and Lerna
In this article, Saiharsha Balasubramaniam shows how to set up and manage a monorepo for a JS project using Yarn Workspaces and Lerna....
Read more >
Gatsby Changelog | 5.3.0
When you saw the error "Building static HTML failed for path . ... gatsby-plugin-preact : Fix exports resolution to get it working with...
Read more >
11.xml - jsDelivr
... ://www.jsdelivr.com/package/npm/@unstoppabledomains/maticjs-resolution monthly ... monthly https://www.jsdelivr.com/package/npm/@util.js/lerna monthly ...
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