Vercel: Windows: Doesn't work because of .bin executable issue

Created on 1 Jun 2017  路  32Comments  路  Source: vercel/vercel

Environment

  • OS: Windows 7/10
  • Node: 8
  • now: latest
  • CLI: git for windows (2.13)

Steps

Install

npm install now

Run

./node_modules/.bin/now -v

Error

./node_modules/.bin/now: line 1: /../now/download/dist/now: No such file or directory

Findings

Current: node_modules/.bin/now

"$basedir/../now/download/dist/now"   "$@"
exit $?

Expected: node_modules/.bin/now

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/../now/download/dist/now" "$@"
  ret=$?
else 
  node  "$basedir/../now/download/dist/now" "$@"
  ret=$?
fi
exit $ret

Note: By making this change it fixes the issue

ESLint example

I used ESLint generated code and replaced the file paths.

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/../eslint/bin/eslint.js" "$@"
  ret=$?
else 
  node  "$basedir/../eslint/bin/eslint.js" "$@"
  ret=$?
fi
exit $ret

Notes/Questions

  • Really not sure why this is happening, maybe how its packaged?
  • We at ESLint doesn't do anything special and all this is generated by npm install process.
  • Sorry if this is duplicate. I did try searching :smile: .

Most helpful comment

Windows 10, Git Bash
$ now.cmd works

All 32 comments

@igorklopov

@gyandeeps why do you use node_modules/.bin/now instead of node_modules/.bin/now.cmd? Do you use Cygwin? Windows prepends extensions like .exe and .cmd once it is going to execute a program. So now files are not executed. Their .exe or .cmd counterparts are executed.

If you delete now.cmd and eslint.cmd from .bin do they stop working? This is a question to get more info about your env.

I am not doing anything special, that how npm works on windows.
example if i want to run eslint i do ./node_modules/.bin/eslint.

I deleted eslint.cmd and it still works.

Well, does node_modules/.bin/now.cmd work?

So whenever you execute a package through npm like

{
     "lint": "eslint"
}

npm run lint: will hit the eslint.cmd to execute that. same goes for things which are installed globally.

Initially I installed now globally and ran the command now. that also when i got the same error. I am using git bash on windows. Not sure if that makes a difference or not. But again just changing that file content made everything work regardless on how you call the command.

I am also getting this issue:

OS: Windows 8.1
Node: Using nodist (multiple versions)
now: latest
CLI: hyper w/ cygwin

Same issue here.

Using git bash (on Windows 10) and installing now globally I get the error:

$ now -v
[...cut $USERPROFILE path...]/AppData/Roaming/npm/now: line 1: /node_modules/now/download/dist/now: No such file or directory

$ now.cmd -v
7.1.1

https://docs.npmjs.com/files/package.json#bin

Please make sure that your file(s) referenced in bin starts with #!/usr/bin/env node, otherwise the scripts are started without the node executable!

For npm to create the shim right, as suggested by @gyandeeps, the script defined in the bin property of package.json must have the shebang line #!/usr/bin/env node.

Any news? 7.2.2 doesn't fix it.

Below the script expected for $USERPROFILE/AppData/Roaming/npm/now:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/now/download/dist/now" "$@"
  ret=$?
else
  node  "$basedir/node_modules/now/download/dist/now" "$@"
  ret=$?
fi
exit $ret

You can notice there is something wrong in the installation because now script doesn't have executable permissions (in git bash environment).

The issue still exists on git bash on windows

@zusamann I don't think the patch was included in the latest version 7.2.4.

Or do you mean you tested the master and it doesn't work?

Oh sorry for the confusion, I simply used the latest release and did not build from master.

7.3.0 works fine. Thanks.

馃憣

Getting this issue today on version 8.1.0, Windows 10, using gitbash.

Anybody have a solution? Keep getting No such file or directory.

same here... I had to use powershell to make it work...

Same on 8.2.1 with git bash...

Sigh. 8.2.1 doesn't work.

See also #729.

+ [email protected]
updated 1 package in 24.149s
16:02:38 [/c/My/Dev]
$ now -v
/c/Users/xobeci/AppData/Roaming/npm/now: line 1: /node_modules/now/download/dist/now: No such file or directory
16:02:57 [/c/My/Dev]
$

Anyway using now.cmd is ok.

We haven't tackled Git for Windows yet, but I suppose we should do that, now that so many people are interested in it. @igorklopov?

now not working on Windows 10 : Git Bash.

Node Version: v8.5.0
NPM Version: v5.4.2

Error: /c/Users//AppData/Roaming/npm/now: line 1: /node_modules/now/download/dist/now: No such file or directory

Content of /c/Users/Nikunj/AppData/Roaming/npm/now

"$basedir/node_modules/now/download/dist/now" "$@"
exit $?

i'm getting the same

I'm no expert but shouldn't now be a shell script? For example, compare cat now and cat tsc:

$ cat /c/Users/Borek/AppData/Roaming/npm/now
"$basedir/node_modules/now/download/dist/now"   "$@"
exit $?
$ cat /c/Users/Borek/AppData/Roaming/npm/tsc
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/typescript/bin/tsc" "$@"
  ret=$?
else
  node  "$basedir/node_modules/typescript/bin/tsc" "$@"
  ret=$?
fi
exit $ret

I think that's what I've seen in most bootstrap scripts.

Windows 10, Git Bash
$ now.cmd works

Sigh again.
Apart a few single releases, like 7.3.0, in 9.0.0-canary.9 there is the issue.

Any news?

@leo are you sure?

Using git bash 2.15.0.windows.1, node 9.1.0 and npm 5.5.1, now is installed locally (and not globally).

$ npm ls now
[email protected] C:\My\Dev\zzz\tobedefined
`-- [email protected]

$ node_modules/.bin/now ls
node_modules/.bin/now: line 1: /../now/download/dist/now: No such file or directory
  • node_modules/.bin/now.cmd ls works.
  • If you use now inside a npm script, it works: "deploy": "now deploy --public && now alias".
  • The installation is fixed (#729).

@albertosantini What command did you use to install it?

npm install now

It should be npm install -g now. The -g flag is required for installing packages globally.

Well... I want to install locally (per project) the package and there should not be any diff in terms of "executable".

At least, I didn't notice any difference using other tools, if they are installed globally or locally.

I don't (cannot) think now doesn't support this use case. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SteveALee picture SteveALee  路  51Comments

remy picture remy  路  42Comments

Warchant picture Warchant  路  27Comments

ghost picture ghost  路  28Comments

mxstbr picture mxstbr  路  34Comments