nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.63k stars 2.36k forks source link

package.json scripts don't work when using `yarn bin _` #10973

Closed mrjackdavis closed 1 year ago

mrjackdavis commented 2 years ago

Current Behavior

Given workspaces/mypkg/package.json contains

{
  scripts:{
    test: "node $(yarn bin jest)"
  }
}

Running yarn nx test mypkg yields MODULE_NOT_FOUND

Screen Shot 2022-07-01 at 12 48 12 pm

Expected Behavior

Given workspaces/mypkg/package.json contains

{
  scripts:{
    test: "node $(which jest)"
  }
}

Running the script produces the correct behaviour (i.e. it doesn't fail). This bug is only evident when running scripts via NX

Steps to Reproduce

  1. Take any nx repo which uses yarn 1 (not sure if this affects other yarn versions)
  2. Replace a package.json script with the yarn bin version of the command. e.g. "test":"jest" becomes "test":"node $(yarn bin jest)"
  3. Run the command yarn nx test mypkg

Failure Logs

REDACTED/node_modules/.bin/jest'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Environment

 >  NX   Report complete - copy this into the issue template

   Node : 16.14.2
   OS   : darwin x64
   yarn : 1.22.10

   nx : 14.3.6
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.3.6
   @nrwl/eslint-plugin-nx : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.3.6
   @nrwl/js : Not Found
   @nrwl/linter : 14.3.6
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/workspace : 14.3.6
   typescript : 4.4.4
   ---------------------------------------
   Community plugins:
     @nx-aws-plugin/nx-aws-cache: 1.1.0
FrozenPandaz commented 2 years ago

I can't reproduce this issue. For me, this works properly:

image

Could you please provide a repo that exhibits the issue? Please make sure you have jest installed locally in the workspace.

If you have jest installed globally but not in the repo, which jest will succeed whereas yarn bin jest will fail:

jason@pop-os ~/p/t/yarn-bin-test (main)> which jest
/usr/local/bin/jest
jason@pop-os ~/p/t/yarn-bin-test (main)> yarn bin jest
error Couldn't find a binary named "jest"
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.