首页 > 解决方案 > “术语 '/node.exe' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称”

问题描述

我正在尝试按照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"
    }
}

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

环境变量

标签: javascriptnode.jscommand-line-interface

解决方案


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

以及为什么在env这里使用而不是node直接调用,在另一篇 SE 帖子中进行了总结。

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


推荐阅读