2

When I run yarn start or any other following scripts:

"scripts": {
        "start": "webpack-dev-server --config scripts/webpack.dev.js",
        "clean": "rimraf build",
        "build": "yarn run clean && yarn run compile",
        "compile": "webpack --config scripts/webpack.prod.js",
        "compile-for-test": "webpack --config scripts/webpack.test.prod.js",
        "build-for-test": "yarn run clean && yarn run compile-for-test",
        "test": "jest -c scripts/jest.config.js --testPathIgnorePatterns=\"services/contract-tests\"",
        "test-ci": "node scripts/test-shell-commands.js unitTestCI",
        "test-contract": "node scripts/test-shell-commands.js testLocal",
        "test-contract-ci": "node scripts/test-shell-commands.js testCI",
        "coverage": "node scripts/test-shell-commands.js unitTestCoverage",
        "lint": "./node_modules/.bin/eslint --max-warnings=0 \"src/**\"",
        "start-backend": "bash -l ./scripts/start-backend-container.sh",
        "stop-backend": "bash -l ./scripts/stop-backend-container.sh",
        "start-stub": "bash -l ./scripts/start-backend-stub-container.sh",
        "stop-stub": "bash -l ./scripts/stop-backend-stub-container.sh",
        "prettier": "prettier --write **/*{ts,tsx}"
    },

I get the following error:

# yarn start
$ webpack-dev-server --config scripts/webpack.dev.js
error Couldn't find the binary webpack-dev-server --config scripts/webpack.dev.js
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

# yarn test
$ jest -c scripts/jest.config.js --testPathIgnorePatterns="services/contract-tests"
error Couldn't find the binary jest -c scripts/jest.config.js --testPathIgnorePatterns="services/contract-tests"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This applies to all scripts (its not spesific to webpack etc). However, when I use it npm run start, it works. yarn add or yarn commands alone also work. Just I can't run any script with yarn.

Does anyone encountered this before?

My yarn version is: 1.22.10 I have uninstalled and installed a few times but the problem continues. OS: Windows

Ozgur
  • 3,738
  • 17
  • 34
  • Is it possible you've used *non-breaking* spaces? – jonrsharpe Jan 29 '21 at 13:30
  • I double-checked but it's not the case. – Ozgur Jan 30 '21 at 14:02
  • It seems like `yarn` is not able to find the executable dependencies when you try to run a `script`. I suggest to remove the `node_modules` folder, run `yarn cache clean`. After that run `yarn install` and try to run `yarn start`. – Milan Tenk Feb 01 '21 at 08:17
  • Are you using Windows? – maltoze Feb 01 '21 at 08:22
  • @maltoze yes I forgot to specify it – Ozgur Feb 01 '21 at 09:53
  • @MilanTenk thans for suggestion, will try and let you know! – Ozgur Feb 01 '21 at 09:53
  • @MilanTenk Unfortunately same error after your proposition, thanks again. – Ozgur Feb 01 '21 at 10:56
  • You are welcome, I have an other question: Is the installed `Node.js` added to the `PATH` in the environmental variables? (You can also check it from command line by running `node --version` from a folder, where the `node.exe` is not there. If `node --version` prints the version, the environmental variable is ok.) – Milan Tenk Feb 01 '21 at 11:20
  • Have you tried this? https://github.com/yarnpkg/yarn/issues/6086#issuecomment-423423144 – maltoze Feb 01 '21 at 11:35
  • 1
    Whats your return on running `yarn config get script-shell`? – iLuvLogix Feb 01 '21 at 14:32
  • 1
    @iLuvLogix after your question I realized it's not looking for correct path.. Please answer with a question and I will accept :) – Ozgur Feb 03 '21 at 05:54

1 Answers1

1

This might be an issue with node trying to spawn a command on windows when specifying bash as the shell since Yarn uses node's child_process.spawn.

The shell-script specified in .yarnrc, passes that shell as the shell option to spawn, and when a shell is specified and process.platform evaluates to win32, ['/d', '/s', '/c' will be tacked in the arguments (see below source of spawn()).

 if (options.shell) {
    const command = [file].concat(args).join(' ');

    if (process.platform === 'win32') {
      if (typeof options.shell === 'string')
        file = options.shell;
      else
        file = process.env.comspec || 'cmd.exe';
      args = ['/d', '/s', '/c', `"${command}"`];
      options.windowsVerbatimArguments = true;

Please check your yarn configuration via yarn config get script-shell in order to verify the settings of the bash-path.

See child_process.spawn for more info..

iLuvLogix
  • 5,920
  • 3
  • 26
  • 43