[英]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
node -v
command and it returned 10.22.1
我通过运行node -v
命令检查节点是否已安装,它返回10.22.1
which node
and it returned /usr/bin/node
我通过运行which node
检查了节点安装在哪里,它返回/usr/bin/node
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.