question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Question: How do I run npm scripts that reference binaries from the root package?

See original GitHub issue

I am hoping to keep all shared devDependencies in the root package to avoid duplication, but this prevents us from running npm scripts directly from the sub-packages. Hereā€™s a concrete example:

Each sub-package defines scripts like this:

  "scripts": {
    ...
    "check": "gts check"
    ...
  }

Our root package is the only package that declares a dependency to gts:

  "packages": {
    ...
    "gts": "^1.1.2",
    ...
  }

I can run this with no problem:

$ lerna run check
<SUCCESS!>

However, we cannot run this from a sub-package (the reason we want to do this is to speed up the running of the scripts, especially when most devs only focus on one of the sub-packages at a time):

$ npm run check
sh: gts: command not found
npm ERR! code ELIFECYCLE
...

This makes sense since gts is not in the sub-packageā€™s node_modules/.bin folder. I could fix the problem if I change the scripts in each sub-package to something like this:

  "scripts": {
    ...
    "check": "PATH=$PATH:../../node_modules/.bin && gts check"
    ...
  }

but, this isnā€™t ideal. For one thing, it does not work on Windows. Another possibility would be to explicitly push all devDependencies down to the sub-packages and nohoist them all. This is not ideal either since we are now duplicating a lot of our packages.

Is there a better solution that doesnā€™t involve package duplication or explicitly adding paths to each of our scripts?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
dcheung2commented, Jun 3, 2020

Using relative path to the cli without change path should work for you

"scripts": {
...
"check": "../../node_modules/.bin/gts check"
...
}

I donā€™t see a prefect way to do it. Even if lerna add some cli to resolve the path, the sub-projects doesnā€™t even know lerna unless you install it as a global tool in your PATH.

another workaround would be, use a shell with the PATH environment variable to the root node_modules/.bin before start working of the day.

which could cause another problem if you work on multiple projects.

1reaction
github-actions[bot]commented, Jun 3, 2022

Hi Folks šŸ‘‹

You may or may not know that lerna is now under the stewardship of Nrwl (announcement here https://github.com/lerna/lerna/issues/3121), a company with a long history of not just producing valuable open-source software (OSS), but also backing others (at the time of writing, Nrwl has donated over $50,000 to OSS it hasnā€™t created, see https://opencollective.com/nx for full details).

Quite simply, Nrwl ā¤ļø OSS, and is committed to making lerna the best it can be. We use it ourselves.

In order to take this awesome project forward from its current state, it is important that we focus our finite resources on what is most important to lerna users in 2022.

With that in mind, we have identified this issue as being potentially stale due to its age and/or lack of recent activity.


Next steps:

We want to give you some time to read through this comment and take action per one of the steps outlined below, so for the next 14 days we will not make any further updates to this issue.

@aeisenberg as the original author of this issue, we are looking to you to update us on the latest state of this as it relates to the latest version of lerna.

Please choose one of the steps below, depending on what type of issue this is:

  • A) If this issue relates to a potential BUG in the latest version of lerna:

  • B) If this issue is a FEATURE request to be added to the latest version of lerna:

    • Simply comment back on this thread so that we know you still want us to consider the request for the latest version of lerna.
  • C) If this issue is a QUESTION which is applicable to latest version of lerna:

  • D) If this issue is no longer applicable to the latest version of lerna:

    • Please close the issue.

If we do not hear from @aeisenberg on this thread within the next 14 days, we will automatically close this issue.

If you are another user impacted by this issue but it ends up being closed as part of this process, we still want to hear from you! Please simply head over to our new issue templates and fill out all the requested details on the template which applies to your situation:

https://github.com/lerna/lerna/issues/new/choose

Thank you all for being a part of this awesome community, we could not be more excited to help move things forward from here šŸ™ šŸš€

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm-run-script
Scripts are run from the root of the package folder, regardless of what the current working directory is when npm run is called....
Read more >
How to use executables from a package installed locally in ...
If you've run npm install with the package.json in your project's main folder, you should have a ./node_modules/.bin/coffee folder in this folder. Using...
Read more >
Scripting inside package.json
Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run...
Read more >
Mastering NPM Scripts - DEV Community ā€ ā€
Now all you need to do is run npm run hello-world on the terminal from your project's root folder. > npm run hello-world...
Read more >
Setting up a Node development environment - MDN Web Docs
In addition to defining and fetching dependencies you can also define named scripts in your package.json files and call npm to execute them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found