Lerna, Yarn & Workspaces path resolution wrong for `preact` / prerender.js
See original GitHub issueDo 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:
- Created 4 years ago
- Reactions:11
- Comments:5
Top GitHub Comments
Small workaround for now, add two packages to your
nohoist
list in your rootpackage.json
:But for the long run, a correct package resolution should be the way to go 😃
Not ideal, but after install I just copy
preact
andpreact-render-to-string
to the packagesnode_modules
. I run a top levelprepare
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: