server icon indicating copy to clipboard operation
server copied to clipboard

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

Open JunSong opened this issue 6 years ago • 25 comments

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

JunSong avatar May 11 '18 09:05 JunSong

Can you run node -v from the same folder?

siburny avatar May 14 '18 12:05 siburny

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

JunSong avatar May 15 '18 03:05 JunSong

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

siburny avatar May 15 '18 11:05 siburny

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.

defunctzombie avatar May 16 '18 15:05 defunctzombie

Yes, it's specific to the Unix flavor.

siburny avatar May 16 '18 16:05 siburny

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

Spown avatar May 16 '18 21:05 Spown

@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.

siburny avatar May 17 '18 11:05 siburny

@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.

Spown avatar May 17 '18 11:05 Spown

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.

siburny avatar May 17 '18 12:05 siburny

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

roccomuso avatar May 18 '18 10:05 roccomuso

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

siburny avatar May 18 '18 13:05 siburny

@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.

roccomuso avatar May 18 '18 14:05 roccomuso

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

kaiye avatar May 22 '18 06:05 kaiye

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

izanagi1995 avatar May 26 '18 11:05 izanagi1995

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

arthot avatar May 30 '18 18:05 arthot

@arthot thanks, it did work for me.

Spown avatar May 30 '18 18:05 Spown

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.

Mike-GKA avatar May 24 '19 09:05 Mike-GKA

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>

eternalsayed avatar Aug 02 '19 21:08 eternalsayed

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?

krynble avatar Oct 27 '20 22:10 krynble

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

siburny avatar Oct 27 '20 22:10 siburny

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.

krynble avatar Oct 28 '20 11:10 krynble

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.

siburny avatar Oct 28 '20 21:10 siburny

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

steven11329 avatar Nov 09 '20 01:11 steven11329

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

MkLHX avatar Jan 27 '21 17:01 MkLHX

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

StyleT avatar Feb 20 '21 06:02 StyleT