【问题标题】:"The term '/node.exe' is not recognized as the name of a cmdlet, function, script file, or operable program"“术语 '/node.exe' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称”
【发布时间】:2021-02-25 22:14:14
【问题描述】:

我正在尝试按照Twilio 上的教程使用 Node.js 制作 CLI,在完成 npm link 之后,我在使用该命令时收到此错误。我读了一篇旧的溢出帖子,上面说要将节点添加到我的环境变量中,我有。

这是错误:

& : The term '/node.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\thedi\AppData\Roaming\npm\create-project.ps1:15 char:5
+   & "/node$exe"  "$basedir/node_modules/@thedigs/create-project/bin/c ...
+     ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (/node.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

这是我当前的代码:

// bin/create-project

#!/usr/bin/env/node

require = require('esm')(module /*, options */);
require('../src/cli').cli(process.argv);


// src/cli.js

export function cli(args) {
    console.log(args);
}

// package.json

{
    "name": "@thedigs/create-project",
    "version": "1.0.0",
    "description": "A CLI to bootstrap my new projects, whatever that means.",
    "main": "src/index.js",
    "scripts": {
        "start": "nodemon ."
    },
    "publishConfig": {
        "access": "public"
    },
    "bin": {
        "@thedigs/create-project": "bin/create-project",
        "create-project": "bin/create-project"
    },
    "keywords": [
        "cli",
        "create-project"
    ],
    "author": "thedigs",
    "license": "ISC",
    "dependencies": {
        "@types/node": "^14.14.31",
        "esm": "^3.2.25",
        "nodemon": "^2.0.7"
    }
}

我最好的猜测是教程落后于版本,希望你们中的一个可以为我解决这个问题。谢谢!

Environment Variables

【问题讨论】:

  • 解决方案在下面的空间中作为答案。不要编辑问题以添加解决方案。
  • 我也有同样的问题
  • 与我的代码比较后,我意识到我们做错了什么。检查出来后添加我的答案是正确的答案。谢谢。

标签: javascript node.js command-line-interface


【解决方案1】:

我也在寻找答案,但是在比较了这段代码之后,我的代码突然意识到#!/usr/bin/env/nodebin/create-project的路径是完全错误的。

在我的例子中,我将它作为#! /user/bin/env node,但它必须是usr,而不是使用user

在这种情况下,它必须是……

文件:bin/create-project

#! /usr/bin/env node

require = require('esm')(module /*, options */);
require('../src/cli').cli(process.argv);

当涉及到路径时,这些空格是必须的。

【讨论】:

    【解决方案2】:

    供参考:第一行是所谓的shebang

    以及为什么在这里使用env而不是直接调用node,在另一个SE帖子中是summarized here

    简短:env 充当代理来查找您想要的解释器,在您的情况下为目标系统上的 node,即使它可能在用户 ~ 主目录或其他东西中找到...

    【讨论】:

      猜你喜欢
      • 2021-11-01
      • 2021-05-23
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多