-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Yarn workspaces: a lot of node_modules
are missing in workspace
#4503
Comments
Hey! This is by design, Yarn hoists all dependencies it can to the workspaces root. Why do you need them inside? |
@BYK Hi, but how to fix this issue? I can't start project, because it can't find for e.g. |
@bsvipas this is not really "fixable" I think. The tool itself would need to check if it is available on the higher level. Can you run things from the workspace root? |
@BYK I can't do that, because I'm using EDIT: |
Basically this happens to me #4081 and I think this is only with Ember... |
@BYK This issue is related with |
Similar issue in create-react-app, what is the problem with the creation of symbolic links in the local packages? |
Symlinks have problems. |
I think this is not Yarn fault, it's because of tools which search for |
@arcanis thanks for the link. @bsvipas yep, it seems that is the create-react-app is guessing the package absolute path. |
This is an issue I'm running into with various tooling. It's not really yarn workspace's fault - it makes sense to push the modules to the parent directory. But it can be frustrating when working with and mixing your other workspace modules as regular node modules within each other. The biggest issue I have is that using auto-import in the IDE's I've been trying (WebStorm and VS Code), trying to auto-complete a class / function from a different workspace package - as in the OP example, something from If there was instead a symlink to the module in the actual workspace folder (only needed for workspace modules) perhaps this could be avoided. As you can open up a new project window in only the folder of each workspace module, which should scope it only to that directory, and check in that |
@lostpebble I can just agree with you. If symlinks was created in all workspaces from the root (project |
@bsvipas we also use monorepo with interconnected Ember addons and we solved the issue by automatically symlinking whatever package specifically requires from a hoisted |
FYI I'm running into this same issue with babel plugins. I'm getting:
Since babel won't look outside of the project folder but the yarn workspace is installing everything in To the various comments in this thread arguing that it's not yarn's fault, I would argue that it is. Yarn workspaces change the expected directory structure that has been consistent since whatever npm version was with node v0.x (for at least top-level modules) |
I'm having this issue as well, in my case with babel. We have a monorepo with a couple rails apps, each of which use webpack to bundle react code. What I don't understand is that even prior to workspaces we had babel specified at the root of the project, and it would get loaded fine because the standard node resolution rules would look up from the rails app's folder to the root and find babel. I'm quite confused as to how this could change when using workspaces, but it seems like every case mentioned here should work just fine thanks to the default resolution rules. No? |
I've had this issue too, but not consistently, so I couldn't really pinpoint the issue... My best guess is that if one of the packages shares all its dependencies with the other packages, they're all hoisted in the root, and that package doesn't even have a it's mostly a problem for binaries that are run form the package with a script pointing to the package's // scripts/link-binaries.js
const { readdir, access } = require('fs');
const { promisify } = require('util');
const { resolve } = require('path');
const shell = require('shelljs');
const { map } = require('ramda');
const asyncReaddir = promisify(readdir);
const asyncAccess = promisify(access);
const packagesDir = resolve(__dirname, '../packages');
const rootDir = resolve(__dirname, '../');
function linkBinaries(_package, nodeModulePath) {
console.log('linking binaries in ', _package);
shell.mkdir(nodeModulePath);
shell.exec(`ln -s ${rootDir}/node_modules/.bin ${nodeModulePath}/.bin`);
}
async function perform() {
const packages = await asyncReaddir(packagesDir);
const result = map(async _package => {
const nodeModulePath = resolve(
packagesDir,
`./${_package}`,
'./node_modules'
);
try {
return await asyncAccess(nodeModulePath);
} catch (e) {
if (e.code === 'ENOENT') {
linkBinaries(_package, nodeModulePath);
return;
}
throw e;
}
}, packages);
return Promise.all(result);
}
const successHandler = () => {
console.log('Binaries linked !');
process.exit(0);
};
const errorHandler = err => {
console.error(err);
process.exit(1);
};
perform().then(successHandler, errorHandler); // in root package.json
"scripts": {
"prepare": "node scripts/link-binaries.js"
} the script could probably be improved, but it fixed the issue for me |
Also having issues with this where hoisting is leading to a number of difficult to resolve bugs in our Typescript setup. In some cases, it's causing duplicated conflicting module declarations and in other cases it's causing it to not find types that would be declared by a peer dependency. The inconsistency of the behavior makes it difficult to address by adjusting the global compiler settings in |
In case it helps anyone else, a hack that seems to work to keep your modules from being hoisted is to install a conflicting version of the same module in the root directory of your monorepo. That way the specific version used by your package will be kept in your respective workspace. For my issue mentioned about the fix was a bit different, I used the |
Tools like react-native link and react-native-git-upgrade seem to have this problem as well. |
|
Perhaps adding a shell This gives the advantage of the root While ideally This could be opt in via a |
Maybe the external tools (ember-cli, webpack etc) should travers upwards until it finds a |
I used to have a similar problem when ussing yarn
I initially solved it by adding But then I upgrade from yarn |
This is an old issue, but I have found a solution if anyone runs into this. Yarn has a somewhat poorly documented It lets you specify packages that you don't want to have hoisted to the top. For example, if you want to completely eliminate the {
"workspaces": {
"packages": [
"projects/*",
],
"nohoist": [
"**"
]
},
} To get this to work, I had to delete my problematic |
I also meet this problem.
But, If I enter the workspace package folder(app-a), and run At the end, I give up, and will try yarn v2 workspace. |
For others looking for answers for Berry, the hoisting behaviour can be adjusted with the https://yarnpkg.com/configuration/yarnrc#nmHoistingLimits option. I was pulling in a third-party package as a workspace and it needed to run a script in one of its dependencies as part of its own |
is there any update on this issue? We are facing a similar situation where the yarn install is not creating node_modules with symlinks in workspaces. Please help |
@vbansal2 use
|
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I have 2 workspaces. In the root dir I created
package.json
:When I use
yarn install
and I go to thefrontend/node_modules
I see just several modules, but not all needed which are in the root dir. As far as I understand there's no symlink created for these packages? For e.g. I needember-pikaday
, but it's not in thefrontend/node_modules
, but it's in the rootnode_modules
.In short: in
frontend/package.json
I haveember-pikaday
, but it's not in the frontend/node_modules afteryarn install
. Because of this I can't start my project (Node.js can't findember-pikaday
and thinks it's not installed).What is the expected behavior?
To get all needed node_modules inside workspaces.
Please mention your node.js, yarn and operating system version.
Node: 7.10.1
Yarn: 1.0.2
macOS
P.S. This feature is AMAZING!
The text was updated successfully, but these errors were encountered: