env: node\r: No such file or directory with cordova cli
Asked Answered
G

5

5

When trying to run cordova cli on OSX get an error

env: node\r: No such file or directory

I got the latest version of cordova from npm so I think it is 3.0.7

Graze answered 28/8, 2013 at 16:1 Comment(0)
G
5

The problem seems to be that cordova is in dos format

once I converted it to Unix format it seems to work. I don't get the env: node\r: No such file or directory error.

I used dos2unix to make the change https://code.google.com/p/rudix/downloads/detail?name=dos2unix-5.3.3-0.pkg

On my machine the cordova file was actually in usr/local/lib/node_modules/cordova/bin/cordova

Graze answered 28/8, 2013 at 16:1 Comment(2)
I think they fixed this bug so if you get the latest version everything should be fine.Graze
Thanks. My problem was from GIT but your answer was instrumental to understand that it was coming from a bad line ending mishap. I added my solution below.Cheston
R
14

Solution:

$ brew install dos2unix
$ find /usr/local/lib/node_modules -name "*.js" | xargs sudo dos2unix

Details:

The problem for OP was to do with Git, However I am taking a moment to mention the quick fix for most of it's cases

The problem will show up if Node tries to execute .js file which has windows style line endings. Problem might come from third party npm packages which has .js files of that kind.

As @Leo mentioned Dos2Unix is the answer, Here is the chain of commands for an example situation while I was trying to install Slack-cli

> npm install -g slack-cli
> slackcli
env: node\r: No such file or directory

The fix looks like

> brew install dos2unix
> find /usr/local/lib/node_modules/slack-cli -name "*.js" | xargs sudo dos2unix
> slackcli --help

Walla..

Reimer answered 25/6, 2015 at 4:8 Comment(0)
G
5

The problem seems to be that cordova is in dos format

once I converted it to Unix format it seems to work. I don't get the env: node\r: No such file or directory error.

I used dos2unix to make the change https://code.google.com/p/rudix/downloads/detail?name=dos2unix-5.3.3-0.pkg

On my machine the cordova file was actually in usr/local/lib/node_modules/cordova/bin/cordova

Graze answered 28/8, 2013 at 16:1 Comment(2)
I think they fixed this bug so if you get the latest version everything should be fine.Graze
Thanks. My problem was from GIT but your answer was instrumental to understand that it was coming from a bad line ending mishap. I added my solution below.Cheston
C
4

On my Mac OS X.

I just ran into the same problem : My files had their line endings changed to CRLF(windows) instead of LS(unix).

It made Cordova and Node unable to compile the project with the error :

env: node\r: No such file or directory

The culprit was GIT which was on AUTOCRLF I don't know why. I ran the following command in the terminal :

git config --global core.autocrlf input

Then I had to delete the project and reclone it from GIT and it worked like a charm.

Cheston answered 26/4, 2015 at 9:22 Comment(1)
Found this to be the easiest/most global solution. Ran that config command, recloned the project, everything worked.Varick
J
0

For me problem is in installed gulp library in file:

'/node_modules/gulp/bin/gulp.js'

It has '\r' in the end of '#!/usr/bin/env node' line. Version:

"github:gulpjs/gulp#4.0"

It was fixed by setting:

git config --global core.autocrlf input

And reloading repository

Jaco answered 31/8, 2017 at 12:52 Comment(0)
H
0

In my case the solution was to run cordova with sudo (ubuntu 20.04)

Hohenstaufen answered 17/5, 2023 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.