Yarn: custom node_modules folder breaks .bin since yarn 0.25.4

Created on 26 Jun 2017  路  15Comments  路  Source: yarnpkg/yarn

In our setting we install all our yarn packages in a different folder then the default node_modules folder with the --modules-folder setting.
e.g.:

yarn --modules-folder vendor/node_modules

What is the current behavior?
The current behaviour (version 0.24.*) will install them in vendor/node_modules/.bin
After upgrading to version 0.25.4 it installs them incorrectly in node_modules/.bin, the packages are still installed in vendor/node_modules and the symlinks in node_modules/.bin still work.
However it seems some of them are missing, as I can't find uglifyjs binary for example in my project in that folder.

What is the expected behavior?
Install the packages as version 0.24.* did by installing them in vendor/node_modules/.bin

node.js v7.10.0
yarn: 0.24.5/0.25.4

cat-bug good first issue help wanted triaged

Most helpful comment

Having the same problem. Came up with this to fix the deployment script while it gets fixed:

yarn install
mkdir -p client/node_modules/.bin
for f in node_modules/.bin/*; do
  FILENAME="$(basename $f)"
  OLD_LINK="$(readlink $f)"
  REPLACE="../../client/node_modules/"
  REPLACE_WITH="../"
  NEW_LINK=$(sed -e "s|$REPLACE|$REPLACE_WITH|g" <<< "$OLD_LINK")
  NEW_PATH="client/node_modules/.bin/$FILENAME"
  ln -sf "$NEW_LINK" "$NEW_PATH"
done
rm -rf node_modules

All 15 comments

The bug should be somewhere in package-linker.js, PR is welcome

Seeing this in 0.27.5 as well.

I'll have a pull-request which kind of fixes this, but it looks like it's a hairier problem than I originally gave it credit for, so I'm not entirely satisfied with my solution. My personal use-case is to get more sanity in Docker dev environments whereby I can use a node_modules folder outside of my source path so that there's no files being written thru docker into my local environment. For the most part, with pushed changes, it works.

It looks to me like the most proper fix might be to adjust the yarn Registry so that it has its own modulesFolder rather than checking for modulesFolder everywhere throughout the code, which is what my pull request does. That said, checking config.modulesFolder seems to be the common pattern throughout the codebase, even if it's unevenly applied.

What was the original intent of --modules-folder supposed to be? In what circumstances is it supposed to work? With which commands?

The original --modules-folder idea IIRC is to support other languages, e.g. python_modules, c_modules.
I agree that it would be better to configure folder in one place

Having the same issue, I see a .bin folder created at the current working directory, but not in my custom path.

[email protected]
[email protected]

@schmunk42 there's a PR opened by @twooster https://github.com/yarnpkg/yarn/pull/3792 since a while now but no fix merged ATM. I experiment the same issue and it's annoying.

Having the same problem. Came up with this to fix the deployment script while it gets fixed:

yarn install
mkdir -p client/node_modules/.bin
for f in node_modules/.bin/*; do
  FILENAME="$(basename $f)"
  OLD_LINK="$(readlink $f)"
  REPLACE="../../client/node_modules/"
  REPLACE_WITH="../"
  NEW_LINK=$(sed -e "s|$REPLACE|$REPLACE_WITH|g" <<< "$OLD_LINK")
  NEW_PATH="client/node_modules/.bin/$FILENAME"
  ln -sf "$NEW_LINK" "$NEW_PATH"
done
rm -rf node_modules

Possible duplicate of #1684.

IGNOREME: I am commenting here so I can easily find this issue again in the future, [since I can't do that by subscribing alone](https://github.com/isaacs/github/issues/283).

@BYK no, it's not a duplicate of #1684. It however is related, but this is a more specific problem and solving it would enable a few use cases even without fixing the problems described in #1684.

By the way, this problem still exists in yarn 1.5.1

bump

It has been more than a year since this has been reported and it's still broken 馃憥

In case other people need a quick monkey-patch 馃寛

RUN \
  yarn --no-emoji --pure-lockfile && \
  mv ./node_modules $NODE_PATH

Also ran into this issue trying to set my node modules in an external path. I'd love to help if possible, can someone point me to the right direction? Maybe I can create a PR.

@pothibo any PRs regarding fixing these issues are always welcome (as long as they do not rewrite too much code, making it risky to merge). Feel free to tag me or @arcanis for reviews if you ever get to submit a PR.

Was this page helpful?
0 / 5 - 0 ratings