Yarn: Cannot execute scripts from ./node_modules/.bin/* as npm does

Created on 3 Nov 2016  路  6Comments  路  Source: yarnpkg/yarn

What is the current behavior?
I get this output when trying to run a command from ./node_modules/.bin:

yarn run mocha -- ./test/**/**.spec.js
'.' is not recognized as an internal or external command,

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

yarn add --dev mocha
yarn run mocha -- ./test/**/**.spec.js

What is the expected behavior?
The command should work and not end abruptly.

Please mention your node.js, yarn and operating system version.
node 6.9.1
npm 3.8.3
Win 10

sample package.json scripts section

...
  "scripts": {
    "build": "./node_modules/.bin/grunt --environment=production build",
    "serve": "./node_modules/.bin/grunt --environment=development serve",
    "grunt": "./node_modules/.bin/grunt",
    "bower": "./node_modules/.bin/bower".
    "mocha": "./node_modules/.bin/mocha"
  }
...

Most helpful comment

The reason Windows uses backslashes for directory separators is because, before they supported directories, the forward slash was used for options.

./node_modules/.bin/grunt is running the . command with /node_modules, /.bin, /grunt flags.

Specifying the node_modules/.bin/ subfolder is completely unnecessary in the scripts section; it's not just yarn that looks in there first, npm does too.

All 6 comments

Might be a Windows issue. Working fine for me on macOS Sierra. BTW, can you please mention yarn version too 馃槃

Ah, sure and sorry, it is the latest v0.16.1

Windows indeed. Should be pretty easy fix I think, problem lies in the different path formats. See here: the run command just takes over your scripts format without normalizing it.

Possible workarounds for now are:

  • drop "./node_modules/.bin/", you should not need this if not running directly from cli
  • don't use those scripts, yarn populates the run automatically with the .bin files, so you could run those commands even without defining it in scripts

Possible fixes are:

  • Regex the scripts before populating them into the run so they drop the ./node_modules/.bin
  • Normalize the script path (if it is a path) before running it

The reason Windows uses backslashes for directory separators is because, before they supported directories, the forward slash was used for options.

./node_modules/.bin/grunt is running the . command with /node_modules, /.bin, /grunt flags.

Specifying the node_modules/.bin/ subfolder is completely unnecessary in the scripts section; it's not just yarn that looks in there first, npm does too.

Trying this with yarn v0.22.0 on Windows 10 with node v7.9.0 it works perfectly. If this isn't an issue anymore please close it otherwise please provide more details on how it's still failing so this can be fixed. 馃憤

{
    "scripts": {
        "build": "./node_modules/.bin/grunt --environment=production build",
        "serve": "./node_modules/.bin/grunt --environment=development serve",
        "grunt": "./node_modules/.bin/grunt",
        "bower": "./node_modules/.bin/bower",
        "mocha": "./node_modules/.bin/mocha"
    },
    "dependencies": {
        "mocha": "^3.2.0"
    }
}
C:\Users\xo\code\yarn-issue\1657>yarn run mocha -- ./test/**/**.spec.js
yarn run v0.22.0
$ ./node_modules/.bin/mocha ./test/**/**.spec.js
Warning: Could not find any test files matching pattern: ./test/**/**.spec.js
No test files found
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It seems it got fixed

Was this page helpful?
0 / 5 - 0 ratings