On windows will get the error:
"scripts": {
"some": "./node_modules/some/some.sh",
}
yarn run some
"." Is not recognized as an internal or external command
Please mention your node.js, yarn and operating system version.
Windows 10
node 5.5.0
This is an old issue also with NPM, which they can not fix for ages: https://github.com/npm/npm/issues/13789 though solution is simple just to fix some lines related to path separator.
This is needs to be fixed some where near:
https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/run.js#L65
Solution to make it runable on windows is to replace / slash with \\ when process.platform is win32, but the problem is that how to replaces only slashes that are in the executable path not in their arguments for example.
"scripts": {
"some": "./node_modules/some/some.sh && ../another.sh slashed/arg",
}
should be transformed to "some": ".\\node_modules\\some\\some.sh && ..\\another.sh slashed/arg",
It appears that this is fixed in 0.19.0. I ran into this bug on Windows by installing yarn with chocolatey, which is still on 0.18.1 https://chocolatey.org/packages/yarn. Is 0.19 stable or is 0.20 going to the be the next stable version? Not sure how the versioning works for yarn yet.
https://github.com/yarnpkg/yarn/releases/tag/v0.19.0
Fix scripts cmd slashes for windows (#2082)
Alex - Wed, 14 Dec 2016 17:02:36 +1100
@ctaggart, I should write a blog post about versioning.
In a few words, stable version is listed in https://yarnpkg.com.
Every couple of weeks we make a "minor" branch cut from current master branch.
For example a branch 0.20-stable is due to be cut.
CI will automatically build the branch HEAD and upload the artifacts to GitHub release marking them as Release Candidates and version 0.20.0.
Once we are happy that 0.20.0 is stable we will mark it so and it can be used by the public.
If there are regressions in 0.20 release we fix them in master and then cherry-pick into 0.20-stable.
After a few cherry-picks we release 0.20.1, 0.20.2 etc. We will mark them as stable if no more bugs are reported.
0.19.1 is in chocolatey already.
So, who wants to send a PR to fix this?
The trick is to add the WIN32 hack to here https://github.com/yarnpkg/yarn/blob/master/src/util/execute-lifecycle-script.js#L145.
I tested a simple
cmd = cmd.replace(/\//g, '\\');
works but I am not 100% confident that this won't break other use cases.
If someone wants to step in sending the PR, adding tests and researching if there is a more elegant solution that would be just great.
In the end this is just a hack for a platform ignorant package but replacing path separators seems like an acceptable way unless we are breaking something else.
Why does not npm fix this?
@bestander did you this? https://github.com/yarnpkg/yarn/pull/2082
Awesome, we even have an implementation with test that works for run.
Just need to enable it for the lifecycle scripts then
I am still getting this error when installing the grpc module even on 0.19.1. I saw @Daniel15 recommended removing the node_modules/.bin from npm scripts, but this isn't an option for grpc.
error C:\myCodeFolder\node_modules\grpc: Command failed.
Exit code: 1
Command: C:\Windows\system32\cmd.exe
Arguments: /d /s /c ./node_modules/.bin/node-pre-gyp install --fallback-to-build
Directory: C:\myCodeFolder\node_modules\grpc
Output:
'.' is not recognized as an internal or external command,
operable program or batch file.
Running npm install or npm rebuild works as expected.
> [email protected] install C:\myCodeFolder\node_modules\grpc
> node-pre-gyp install --fallback-to-build
[grpc] Success: "C:\myCodeFolder\node_modules\grpc\src\node\extension_binary\grpc_node.node" is installed via remote
I also did @bestander's cmd = cmd.replace(/\//g, '\\'); and that seemed to work. Is anyone else running into this error? should cmd = cmd.replace(/\//g, '\\'); be added as the solution?
node --version
v6.9.4
npm --version
4.1.2
yarn --version
0.19.1
OS: Windows 10 Enterprise
Better use the class from #2082 instead of regex.
Care to send a PR?
late to the party, but always good to remind people of this (or make sure they're aware of this, if they don't know this yet): the notion that "/ should become \\" is not actually true, and has never been true: Microsoft operating systems have supported / delimiters since their inception and don't need to be rewritten. The real requirement is that locations with spaces or / must be enclosed by double quotes in order to be executed correctly, so the original command as written should be perfectly fine when issued through yarn to the OS, but that command needs to be quoted:
"scripts": {
"some": "\"./node_modules/some/some.sh\"",
}
which is a little ugly thanks to JSON double quote rules, so doing the quoting automatically might be nicer, but of course less correct wrt to what you're write on the CLI.
(ignoring the fact that sh files won't execute natively on Windows)
@Pomax just tried that out and it does not work
Replacing / with \\ does though
"it does not work" isn't really a useful description though: what did you write, and how did it not work? (because Windows most assuredly supports / just fine, but _must_ have query args double-quoted in the standard CLI -- I have no idea what Powershell needs, which is a completely different shell environment and isn't even compatible with standard shell syntax like &)
Most helpful comment
This is needs to be fixed some where near:
https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/run.js#L65
Solution to make it runable on windows is to replace
/slash with\\whenprocess.platformiswin32, but the problem is that how to replaces only slashes that are in the executable path not in their arguments for example.should be transformed to
"some": ".\\node_modules\\some\\some.sh && ..\\another.sh slashed/arg",