"/" is not recognized as an internal or external command

331 Views Asked by At

Today, I'm coding a few npm packages and a few things that need to be prepared repeatedly.

So I wanted to code a CLI to get those things done quickly.

Here is the src/cli.js code:

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

Here is the package.json code:

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "A CLI to bootstrap new project",
  "main": "src/index.js",
  "bin": {
    "@kensoni/my-project": "bin/my-project",
    "my-project": "bin/my-project"
  },
  "publishConfig": {
    "access": "public"
  },
  "keywords": [
    "cli"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Ken Nguyen",
  "license": "MIT",
  "dependencies": {
    "arg": "^5.0.0",
    "esm": "^3.2.25",
    "inquirer": "^8.1.1"
  }
}

Here is the bin/my-project code:

#!/usr/bin/env/ node

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

After I execute the command npm link and open a new cmd type my-project, I get the following message:

'"/"' is not recognized as an internal or external command,
operable program or batch file.

I am using these versions:

  • node: 14.17.1
  • npm: 7.18.1

Any ideas how it might work.

Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

Remove "/" after env

#!/usr/bin/env node

//...