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:
yarnpreact-clilernaEasy 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
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?
Running into the same issue as this when using preact-cli inside a mono-repo. Is there any progress on this issue?
The only workaround for me was disabling yarn workspaces for lerna.
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",
}
...
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 :)
Most helpful comment
Small workaround for now, add two packages to your
nohoistlist in your rootpackage.json:But for the long run, a correct package resolution should be the way to go :)