Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When working in a monorepo using Yarn workspaces and the dependencies for an electron app are hoisted to root, when you run lerna bootstrap the electron app is no longer operable from the scripts in package.json
"start": "electron ."
Error
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
Directory
- desktop/electron (app-desktop)
-- index.html
-- index.js
-- package.json
packages
- components
-- component 1 (component-one)
--- index.js
--- package.json
-- component 2 (component-two)
--- index.js
--- package.json
lerna.json
package.json
lerna.json
{
"lerna": "2.0.0",
"version": "0.0.2",
"npmClient": "yarn",
"useWorkspaces": true,
"commands": {
"publish": {
"ignore": "app-*"
}
}
}
root package.json
{
"name": "root",
"version": "0.0.1",
"description": "Monorepo",
"private": true,
"workspaces": [
"packages/components/*",
"apps/*"
],
"devDependencies": {
"lerna": "^2.0.0"
}
}
Desktop/Electron app package.json
{
"name": "app-desktop",
"version": "0.0.1",
"description": "Desktop app",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"component-one": "^0.0.2",
"component-two": "^0.0.2",
"electron": "^1.6.11",
"electron-compile": "^6.4.1",
"electron-prebuilt-compile": "^1.6.11"
}
}
If the current behavior is a bug, please provide the steps to reproduce.
Sample repo & instructions
What is the expected behavior?
Running yarn start should trigger electron app to launch.
Please mention your node.js, yarn and operating system version.
Node.js -v : 8.2.1
yarn -v : 0.27.5_1
OS -v : macOS Sierra v10.12.6
This also breaks other tools like React Native. I'm guessing that hoisting the dependencies to the root seems to break the scripts being called to run them.
Error: React native is not installed. Please run `npm install` in your project directory.
Also breaks Meteor - it does not look at packages in parent node_modules. When I asked them to support that, they answered:
Meteor does not, and will not ever, consider node_modules directories outside your application root directory, because that would require you to somehow recreate that surrounding environment on the server where you deploy your app. The app should be self-contained.
(benjamn, core member)
If there was a way to indicate that a certain directory should have all it's package.json packages available in it's local node_modules, for example through a flag in package.json (even if these were just symlinks to the parent node_modules), this would work.
Currently it works if we symlink all packages from the root node_modules to our Meteor app node_modules, however if I try to install a new package from within the Meteor folder, yarn deletes all packages in the Meteor node_modules folder, breaking it again.
support for nohoist has been added by #4979 and is available in Yarn v1.5.0+.
check nohoist in Workspaces.
@robdonn please consider closing this issue.
I've defined my mono-repo root's package.json as below and it seems to work...
{
"private": true,
"workspaces": {
"packages": [
"shared-logic",
"electron-app",
"react-native-app"
],
"nohoist": [
"**/react-native", "**/react-native/**",
"**/electron", "**/electron/**",
"**/jest", "**/jest/**"
]
}
}
so far no compilation errors and apps run both on the electron and react native side.
Most helpful comment
Also breaks Meteor - it does not look at packages in parent node_modules. When I asked them to support that, they answered:
If there was a way to indicate that a certain directory should have all it's package.json packages available in it's local node_modules, for example through a flag in package.json (even if these were just symlinks to the parent node_modules), this would work.
Currently it works if we symlink all packages from the root node_modules to our Meteor app node_modules, however if I try to install a new package from within the Meteor folder, yarn deletes all packages in the Meteor node_modules folder, breaking it again.