run npm command gives error "/usr/bin/env: 'node -r esm': No such file or directory" #90

Open
opened 2018-05-11 09:07:50 +00:00 by JunSong · 25 comments
JunSong commented 2018-05-11 09:07:50 +00:00 (Migrated from github.com)

When I run 'bin/server --port 1234', it gives errorr as the title descript.
And my system is Ubuntu 16.04.3 LTS

When I run 'bin/server --port 1234', it gives errorr as the title descript. And my system is Ubuntu 16.04.3 LTS
siburny commented 2018-05-14 12:25:49 +00:00 (Migrated from github.com)

Can you run node -v from the same folder?

Can you run `node -v` from the same folder?
JunSong commented 2018-05-15 03:26:10 +00:00 (Migrated from github.com)

Of course, it show 'v8.9.0'.
And I try run sudo ln -s /usr/bin/nodejs /usr/bin/node, after it tips that ln: failed to create symbolic link '/usr/bin/node': File exists

Of course, it show 'v8.9.0'. And I try run `sudo ln -s /usr/bin/nodejs /usr/bin/node`, after it tips that `ln: failed to create symbolic link '/usr/bin/node': File exists`
siburny commented 2018-05-15 11:54:37 +00:00 (Migrated from github.com)

Try starting the server without use of npm like this:
node -r esm ./bin/server

Update: here is why it doesn't work for you: #! does not allow passing multiple argument to the interpreter. More info here: https://unix.stackexchange.com/questions/63979/shebang-line-with-usr-bin-env-command-argument-fails-on-linux

Try starting the server without use of `npm` like this: `node -r esm ./bin/server` **Update:** here is why it doesn't work for you: `#!` does not allow passing multiple argument to the interpreter. More info here: https://unix.stackexchange.com/questions/63979/shebang-line-with-usr-bin-env-command-argument-fails-on-linux
defunctzombie commented 2018-05-16 15:27:23 +00:00 (Migrated from github.com)

This has worked for me locally (on my mac) for some time - is this specific to linux? Maybe some bash versions?

The -r esm is required for the import syntax I am using however I am happy to add a package.json launch script or other documentation to the readme to make launching the server clearer.

This has worked for me locally (on my mac) for some time - is this specific to linux? Maybe some bash versions? The `-r esm` is required for the `import` syntax I am using however I am happy to add a package.json launch script or other documentation to the readme to make launching the server clearer.
siburny commented 2018-05-16 16:01:40 +00:00 (Migrated from github.com)

Yes, it's specific to the Unix flavor.

Yes, it's specific to the Unix flavor.
Spown commented 2018-05-16 21:52:32 +00:00 (Migrated from github.com)

Same here. Only I'm not running localtunnel server manually but via pm2. It errors with

/var/opt/localtunnel/localtunnel-server/bin/server:3
import 'localenv';
^^^^^^

SyntaxError: Unexpected token import
    at new Script (vm.js:51:7)
    at createScript (vm.js:136:10)
    at Object.runInThisContext (vm.js:197:10)
    at Module._compile (internal/modules/cjs/loader.js:618:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:78:21)
    at Module._compile (internal/modules/cjs/loader.js:654:30)

When I try to run it manually I get

/usr/bin/env: node -r esm: No such file or directory
Same here. Only I'm not running localtunnel server manually but via [pm2](/Unitech/PM2/). It errors with ``` /var/opt/localtunnel/localtunnel-server/bin/server:3 import 'localenv'; ^^^^^^ SyntaxError: Unexpected token import at new Script (vm.js:51:7) at createScript (vm.js:136:10) at Object.runInThisContext (vm.js:197:10) at Module._compile (internal/modules/cjs/loader.js:618:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) at Module.load (internal/modules/cjs/loader.js:566:32) at tryModuleLoad (internal/modules/cjs/loader.js:506:12) at Function.Module._load (internal/modules/cjs/loader.js:498:3) at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:78:21) at Module._compile (internal/modules/cjs/loader.js:654:30) ``` When I try to run it manually I get ``` /usr/bin/env: node -r esm: No such file or directory ```
siburny commented 2018-05-17 11:31:28 +00:00 (Migrated from github.com)

@Spown try running directly through node node -r esm ./bin/server

  • if the first case, pm2 call doesn't include required library esm
  • if the second case, you are hitting the same problem as OP.
@Spown try running directly through node `node -r esm ./bin/server` * if the first case, pm2 call doesn't include required library `esm` * if the second case, you are hitting the same problem as OP.
Spown commented 2018-05-17 11:42:46 +00:00 (Migrated from github.com)

@siburny that's not how pm2 does things. anyway I'm not in a hurry. I'm sure when the OP problem is fixed - pm2'll start working as well.

@siburny that's not how pm2 does things. anyway I'm not in a hurry. I'm sure when the OP problem is fixed - pm2'll start working as well.
siburny commented 2018-05-17 12:30:09 +00:00 (Migrated from github.com)

You are right: I am not sure how pm2 works. I am just telling you what that error means. import is not available in nodejs 8 so one needs to load esm library before executing server script.

You are right: I am not sure how pm2 works. I am just telling you what that error means. `import` is not available in nodejs 8 so one needs to load `esm` library before executing `server` script.
roccomuso commented 2018-05-18 10:35:02 +00:00 (Migrated from github.com)

I'm having the same issue on node 4.2.6 with Ubuntu.

I'm having the same issue on node 4.2.6 with Ubuntu.
siburny commented 2018-05-18 13:07:35 +00:00 (Migrated from github.com)

@roccomuso can you please try running node -r esm ./bin/server as well and let us know if it's working that way?

@roccomuso can you please try running `node -r esm ./bin/server` as well and let us know if it's working that way?
roccomuso commented 2018-05-18 14:31:18 +00:00 (Migrated from github.com)

@siburny No it's not working.
The only thing that worked for me (node 8) was to remove the shebang and put node -r esm ./bin/server inside the package.json as "start" shortcut.

@siburny No it's not working. The only thing that worked for me (node 8) was to remove the shebang and put `node -r esm ./bin/server` inside the `package.json` as "start" shortcut.
kaiye commented 2018-05-22 06:29:15 +00:00 (Migrated from github.com)

@siburny
node -r esm ./bin/server works good on centos 7

@siburny `node -r esm ./bin/server` works good on centos 7
izanagi1995 commented 2018-05-26 11:35:38 +00:00 (Migrated from github.com)

Maybe this can help : https://github.com/standard-things/esm it's a polyfill for older versions of node

Maybe this can help : https://github.com/standard-things/esm it's a polyfill for older versions of node
arthot commented 2018-05-30 18:16:30 +00:00 (Migrated from github.com)

I believe it's something highly pm2-specific, because I overcame this just by restarting/updating pm2: pm2 update. First I've added "node_args" : "-r esm" to my config file, but this also haven't worked out although I began to get another error. And only after restarting pm2 localtunnel started to work.
It may look silly, but judging by this pm2 issue pm2 may have some problem.
Anyway I've solved this problem without updating any of pm2 files, but just by changing pm2 config and restart

I believe it's something highly pm2-specific, because I overcame this just by restarting/updating pm2: `pm2 update`. First I've added `"node_args" : "-r esm"` to my config file, but this also haven't worked out although I began to get another error. And only after restarting pm2 localtunnel started to work. It may look silly, but judging by [this pm2 issue](https://github.com/Unitech/pm2/issues/1943) pm2 may have some problem. Anyway I've solved this problem without updating any of pm2 files, but just by changing pm2 config and restart
Spown commented 2018-05-30 18:34:44 +00:00 (Migrated from github.com)

@arthot thanks, it did work for me.

@arthot thanks, it did work for me.
Mike-GKA commented 2019-05-24 09:21:26 +00:00 (Migrated from github.com)

All the solutions above doesn't help me.
I'm really not an expert in this stuff, but I got an other solution.

I wrote a small script:
#!/bin/bash
cd <yourpath>/localtunnel-server
node -r esm ./bin/server --port 1234

Of course <yourpath> must be adapted to your installation.

Starting the server with this script works fine for me.
Also starting this script with pm2 works for me.

All the solutions above doesn't help me. I'm really not an expert in this stuff, but I got an other solution. I wrote a small script: `#!/bin/bash` `cd <yourpath>/localtunnel-server` `node -r esm ./bin/server --port 1234` Of course `<yourpath>` must be adapted to your installation. Starting the server with this script works fine for me. Also starting this script with pm2 works for me.
eternalsayed commented 2019-08-02 21:36:04 +00:00 (Migrated from github.com)

All the solutions above doesn't help me.
I'm really not an expert in this stuff, but I got an other solution.

I wrote a small script:
#!/bin/bash
cd <yourpath>/localtunnel-server
node -r esm ./bin/server --port 1234

Of course <yourpath> must be adapted to your installation.

Starting the server with this script works fine for me.
Also starting this script with pm2 works for me.

This is what worked for me. I had to change/add 'exec_interpreter' in my pm2.config.json file with value 'bash'. Also, for you to be able to connect to your lt server, you might need to change the above command as below:
#!/bin/bash
cd <your-tunnel-server-directory>
node -r esm ./bin/server --port <YOUR PORT> --net host --domain <eg, sub.domain.com. Base domain/subdomain where you want your tunnelservert to be hosted>

> All the solutions above doesn't help me. > I'm really not an expert in this stuff, but I got an other solution. > > I wrote a small script: > `#!/bin/bash` > `cd <yourpath>/localtunnel-server` > `node -r esm ./bin/server --port 1234` > > Of course `<yourpath>` must be adapted to your installation. > > Starting the server with this script works fine for me. > Also starting this script with pm2 works for me. This is what worked for me. I had to change/add 'exec_interpreter' in my pm2.config.json file with value 'bash'. Also, for you to be able to connect to your lt server, you might need to change the above command as below: `#!/bin/bash` `cd <your-tunnel-server-directory>` `node -r esm ./bin/server --port <YOUR PORT> --net host --domain <eg, sub.domain.com. Base domain/subdomain where you want your tunnelservert to be hosted>`
krynble commented 2020-10-27 22:19:39 +00:00 (Migrated from github.com)

Had the issue with /usr/bin/env: node -r esm: No such file or directory and had it solved using node -r esm ./bin/server but now I'm getting this error with node 14.15.0:

file:///root/server/bin/server:1
SyntaxError: Error parsing /root/server/node_modules/localenv/package.json: Unexpected token , in JSON at position 1492
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) {
  path: '/root/server/node_modules/localenv/package.json'
}

Any ideas?

Had the issue with `/usr/bin/env: node -r esm: No such file or directory` and had it solved using `node -r esm ./bin/server` but now I'm getting this error with node 14.15.0: ``` file:///root/server/bin/server:1 SyntaxError: Error parsing /root/server/node_modules/localenv/package.json: Unexpected token , in JSON at position 1492 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) { path: '/root/server/node_modules/localenv/package.json' } ``` Any ideas?
siburny commented 2020-10-27 22:47:55 +00:00 (Migrated from github.com)

It looks like .json file is corrupt. Can you post it somewhere? Or use online JSON validator.

Update: I am referring to /root/server/node_modules/localenv/package.json file

It looks like .json file is corrupt. Can you post it somewhere? Or use online JSON validator. *Update:* I am referring to `/root/server/node_modules/localenv/package.json` file
krynble commented 2020-10-28 11:39:20 +00:00 (Migrated from github.com)

I took a good look at the file and it seems ok. I used JSON validators and JSON lint, it's all right.

The position mentioned (1492) in the error is the last byte of the file. It's exactly the file length and there is nothing at the end of the file, except for the closing brackets and EOF.

I took a good look at the file and it seems ok. I used JSON validators and JSON lint, it's all right. The position mentioned (1492) in the error is the last byte of the file. It's exactly the file length and there is nothing at the end of the file, except for the closing brackets and EOF.
siburny commented 2020-10-28 21:25:01 +00:00 (Migrated from github.com)

I was able to reproduce this error on the fresh installation. Version of esm module is outdated in package-lock.json. You should upgrade it with npm install esm@3, and then it will work fine.

I was able to reproduce this error on the fresh installation. Version of `esm` module is outdated in package-lock.json. You should upgrade it with `npm install esm@3`, and then it will work fine.
steven11329 commented 2020-11-09 01:39:02 +00:00 (Migrated from github.com)

It works for me by follow

  1. npm install esm@3
  2. Edit bin/server from #!/usr/bin/env node -r esm to #!/usr/bin/env -S node -r esm

Environment:

Platform: GCE
OS: Debian 10
NodeJS Version: 14.15.0

It works for me by follow 1. `npm install esm@3` 2. Edit bin/server from `#!/usr/bin/env node -r esm` to `#!/usr/bin/env -S node -r esm` Environment: > Platform: GCE > OS: Debian 10 > NodeJS Version: 14.15.0
MkLHX commented 2021-01-27 17:10:38 +00:00 (Migrated from github.com)

Hi there fresh install on ubuntu 20.04 LTS
fixed by @steven11329 recap

Hi there fresh install on ubuntu 20.04 LTS fixed by @steven11329 recap
StyleT commented 2021-02-20 06:06:30 +00:00 (Migrated from github.com)

Fixed this issue here https://github.com/StyleT/mytunnel-server It now runs on latest Node.js LTS.

Fixed this issue here https://github.com/StyleT/mytunnel-server It now runs on latest Node.js LTS.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hoelee/server#90