简体   繁体   English

无法在 linux 中运行文件,/usr/bin/env: node: No such file or directory

[英]cannot run a file in linux, /usr/bin/env: node: No such file or directory

OS: Linux(running inside docker) node version: 10.22.1操作系统:Linux(在 docker 内运行)节点版本:10.22.1

I have the executeJs file below:我有下面的 executeJs 文件:

#!/usr/bin/env node
var path = require('path');

var apJsFile = path.resolve(__dirname, '../app.js'); //app.js is working correctly

require(appJsFile);

When I try to execute it ./executeJs it throws the error: : No such file or directory当我尝试执行它时./executeJs它抛出错误: : No such file or directory

  • I checked if the node was installed, by running the node -v command and it returned 10.22.1我通过运行node -v命令检查节点是否已安装,它返回10.22.1
  • I checked where was the node installed by running the which node and it returned /usr/bin/node我通过运行which node检查了节点安装在哪里,它返回/usr/bin/node
  • I checked the path variable by running echo $PATH and it returned /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin我通过运行echo $PATH检查了路径变量,它返回了/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I don't understand why shebangs is not working #!/usr/bin/env node .我不明白为什么 shebangs 不起作用#!/usr/bin/env node

I will appreciate any help in solving this issue.我将不胜感激解决此问题的任何帮助。

# cat /node/scraper/bin/scraper
#!/usr/bin/env node
var path = require('path');
console.log(path);
var scraperJsFile = path.resolve(__dirname, '../scraper.js');
console.log(scraperJsFile);
require(scraperJsFile);
# which node
/usr/bin/node
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# ./node/scraper/bin/scraper
/bin/sh: 72: ./node/scraper/bin/scraper: not found
# /usr/bin/env
JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
HOSTNAME=84ad4665cc48
HOME=/root
OLDPWD=/node/scraper/bin
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
PWD=/usr/bin
# cd /node/scraper/bin
# ls -la
total 20
drwxr-xr-x 2 root root 4096 Jul 13 14:46 .
drwxr-xr-x 8 root root 4096 Jul  8 16:03 ..
-rwxr-xr-x 1 root root  183 Jul 13 14:46 scraper
-rw-r--r-- 1 root root  187 Jul 13 12:52 scraper.bak
-rwxr-xr-x 1 root root  156 Mar 16 17:34 scraper.bat
# ./scraper
/bin/sh: 81: ./scraper: not found

The problem with why the shebangs for the node was not being recognized inside Linux Docker container was the content formatted in windows style for the executeJs file.为什么在 Linux Docker 容器中无法识别节点的 shebangs 的问题是executeJs文件的 Windows 样式格式的内容。 This came due to the mounted volume of the docker container with the host system.这是由于 docker 容器与主机系统的安装卷。 Since my host system is Windows it had formatted executeJs in windows formatting style.由于我的主机系统是 Windows,它以 Windows 格式化样式格式化了executeJs I changed the formatted text style to Linux and everything is working correctly.我将格式化文本样式更改为 Linux,一切正常。

I opened the file with the vi editor and pasted the content and was able to run the executeJs file.我用 vi 编辑器打开了文件并粘贴了内容,然后就可以运行executeJs文件了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法安装 NodeJs: /usr/bin/env: node: 没有那个文件或目录 - Cannot install NodeJs: /usr/bin/env: node: No such file or directory / usr / bin / env:节点--harmony:没有这样的文件或目录 - /usr/bin/env: node --harmony: No such file or directory Jenkins - /usr/bin/env: 节点:没有这样的文件或目录 - Jenkins - /usr/bin/env: node: No such file or directory #!/ usr / bin / env:没有这样的文件或目录 - #!/usr/bin/env: No such file or directory 永远节点/ usr / bin / env:node:没有这样的文件或目录 - Node forever /usr/bin/env: node: No such file or directory / usr / bin / env:“节点”:运行vscode任务时,没有这样的文件或目录 - /usr/bin/env: ‘node’: No such file or directory when running vscode task Jenkins 管道中的错误“/usr/bin/env:'node': No such file or directory” - Error "/usr/bin/env:'node': No such file or directory" in Jenkins pipeline CRON JOB ERROR / usr / bin / env:节点:没有这样的文件或目录 - CRON JOB ERROR /usr/bin/env: node: No such file or directory / usr / bin / env:节点:没有这样的文件或目录,c ++ - /usr/bin/env: node: No such file or directory , c++ http-server-usr / bin / env:node:没有这样的文件或目录 - http-server-usr/bin/env : node : no such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM