Skip to content
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

workspaces: "yarn run" inside a package should run binaries from root node_modules #6148

Closed
AviVahl opened this issue Jul 24, 2018 · 14 comments
Assignees
Labels

Comments

@AviVahl
Copy link

AviVahl commented Jul 24, 2018

Do you want to request a feature or report a bug?
feature request for better usability of workspaces

What is the current behavior?
yarn run only runs bins that were specified in the package itself, not ones from workspace's root package.json.

If the current behavior is a bug, please provide the steps to reproduce.

git clone https://github.com/wixplosives/sample-monorepo
cd sample-monorepo
yarn
# next one works!
yarn run webpack --version
cd ./packages/app
# next one fails :(
yarn run webpack --version

What is the expected behavior?
It should also find binaries from root node_modules, and run them with cwd set to the current package I'm in.

Please mention your node.js, yarn and operating system version.
node 8.11.3, yarn 1.9.1, fedora 28

@ghost ghost assigned rally25rs Jul 24, 2018
@ghost ghost added the triaged label Jul 24, 2018
@pronebird
Copy link

pronebird commented Aug 21, 2018

That actually should work because I believe yarn creates node_modules/.bin/ under each package.

However, you should be able to achieve the same by going through yarn workspace from root workspace, i.e:

yarn workspace {package-name} run webpack --version

@AviVahl
Copy link
Author

AviVahl commented Aug 21, 2018

yarn only creates the .bin folder if those dev deps also appear in the internal package.json, which is not the case here, as I wanted to manage the version of webpack from a single place in the monorepo.

I'll check out the workspace command... thx for the tip @pronebird

@alexindigo
Copy link

Same here. We have jest as shared dev dependency, and when we run yarn workspaces run test, we get:

yarn workspaces run test
yarn workspaces v1.10.1
yarn run v1.10.1
$ jest --collectCoverageFrom=src/**/*.js src
/bin/sh: jest: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1

In order for it to work we have to run:

$ PATH=${PATH}:${PWD}/node_modules/.bin yarn workspaces run test

Not sure why yarn doesn't do it by default.

@KaelWD
Copy link

KaelWD commented Feb 24, 2019

Scripts can run binaries from the root, but yarn run can't.

In a workspace with typescript in the root package:

  "scripts": {
    "build": "tsc"
  }

yarn build works but yarn run tsc doesn't.

@AviVahl
Copy link
Author

AviVahl commented Apr 7, 2019

appears fixed in yarn@1.15.2 :D

@AviVahl AviVahl closed this as completed Apr 7, 2019
@uncleramsay
Copy link

This doesn't appear to be fixed for me?

package.json (this is inside a monorepo)

"scripts": {
    "build:dev": "yarn lerna run build:dev",
  },
  "devDependencies": {
    "lerna": "^3.3.0"
  }
$ yarn build:dev
yarn run v1.15.2
$ yarn lerna run build:dev
error Command "lerna" not found.

@AviVahl
Copy link
Author

AviVahl commented Apr 8, 2019

In the package.json script just use "lerna ..." directly instead of "yarn lerna ...". It works.

@uncleramsay
Copy link

@AviVahl Nope I tried that too:

package.json

  "scripts": {
    "build:dev": "lerna run build:dev",
  },
"devDependencies": {
    "lerna": "^3.3.0"
  }
$ yarn build:dev
yarn run v1.15.2
$ lerna run build:dev
'lerna' is not recognized as an internal or external command,
operable program or batch file.

I see now that it's a slightly different error message, but it still doesn't work...

@KaelWD
Copy link

KaelWD commented Apr 9, 2019

It's working for my scenario with tsc, and lerna works too even though it's only in the root package:

~/Documents/vuetifyjs/vuetify/packages/vuetify
❯ yarn lerna run lint
yarn run v1.15.2
$ /home/kael/Documents/vuetifyjs/vuetify/node_modules/.bin/lerna run lint
lerna notice cli v3.13.1
lerna info Executing command in 3 packages: "yarn run lint"
lerna info run Ran npm script 'lint' in 'vuetify' in 19.4s:
$ concurrently -n "tsc,tslint,eslint,types" --kill-others-on-fail "tsc --noEmit --pretty" "tslint -p . src/**/*.ts -t verbose" "eslint --ext .js,.ts src" "yarn test:types"
[types] $ tsc -p ./types/test/tsconfig.json
[types] yarn test:types exited with code 0
[tslint] tslint -p . src/**/*.ts -t verbose exited with code 0
[tsc] tsc --noEmit --pretty exited with code 0
[eslint] eslint --ext .js,.ts src exited with code 0
lerna info run Ran npm script 'lint' in '@vuetify/kitchen' in 3.9s:
$ eslint --ext .js,.vue src
lerna info run Ran npm script 'lint' in 'vuetifyjs.com' in 12.4s:
$ eslint --ext .js,.vue,.json src
lerna success run Ran npm script 'lint' in 3 packages in 31.9s:
lerna success - vuetifyjs.com
lerna success - @vuetify/kitchen
lerna success - vuetify
Done in 32.55s.

@uncleramsay do you have a node_modules/.bin/lerna anywhere?

@uncleramsay
Copy link

Yeah, I have it at the root of my monorepo. Confused why my scenario is different :S

@AviVahl
Copy link
Author

AviVahl commented Apr 15, 2019

Try the steps in the top of this issue. Does that work on your system?

@aaronleesmith
Copy link

This should not be closed, it's still a very open issue with Yarn 1.17.3.

@AviVahl
Copy link
Author

AviVahl commented Aug 31, 2019

the steps which I've described in the top of this issue work well now.
so, for me, in my specific setup, issue is closed.

please clarify what you mean by open? are you experiencing it when using the same steps?
can you link to any repository in which this issue reproduces for? providing further information, like environment details and steps to reproduce is crucial.

If you're experiencing the same issue, I'll reopen this one.

@ivawzh
Copy link

ivawzh commented Jul 8, 2020

Hi, I am wondering without no-hoist, how can I run a script like this while inside a subpackage:

"typeorm": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' node --require ts-node/register ./node_modules/typeorm/cli.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants