节点脚本可执行文件在Mac上不起作用:env:node\r:没有这样的文件或目录 [英] Node script executable not working on Mac : env: node\r: No such file or directory

查看:56
本文介绍了节点脚本可执行文件在Mac上不起作用:env:node\r:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了我的节点脚本可执行文件来执行某些任务。在Windows上,我的节点脚本可以正常工作。但是在Mac OS X(优胜美地)上,它无法正常工作。

I have created my node script executable to execute some tasks grunt. On Windows, my node script works fine. But on Mac OS X (Yosemite), it's not working.

我的节点脚本已在Windows上发布。

My node script has been published on Windows.

我的节点脚本是通过npm命令安装的:

My node script is installed via npm command :

npm install -g task-app

我的节点脚本的第一行是:

My node script have this first line :

#! /usr/bin/env node

我尝试了许多解决方案来解决我的问题,但我仍然卡住。

I tried many some solutions to solve my problem but I'm still stuck.

这是我使用的以下解决方案:

Here's these solutions that I used :


  1. 卸载并重新安装Node.js

  2. 执行此命令以
    创建节点链接:sudo ln -s / usr / bin / nodejs
    / usr / local / bin / node

  3. 使用以下命令设置路径:export PATH = $ PATH:/ usr / local / bin / node

您还有其他建议方案吗?

Do you have other solutions to propose ?

编辑:

我的脚本的开头:

#! /usr/bin/env node

var grunt = require('grunt');

//Get parameters from command line
var args = process.argv.splice(2);

[...]


推荐答案

<毕竟,我找到了解决问题的办法。

After all, I found the solution to my problem.

由于我的节点脚本文件已在Windows上创建,因此该文件为DOS格式(我认为行尾为DOS格式)。因此,我使用了一个允许将文件转换为unix格式的模块:

As my node script file has been created on Windows, the file is DOS format (line endings in DOS format I think). So, I used a module which allow to converting a file to a unix format :

brew install dos2unix
sudo dos2unix /usr/local/lib/node_modules/task-app/src/task-app.js

这篇关于节点脚本可执行文件在Mac上不起作用:env:node\r:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆