我的步骤
1.新建文件夹test,并进入;
2.执行npm init 生成package.json文件;
3.同级目录下新建hello.js,内容如下:
'use strict';
console.log('123');
4.在 package.json
里添加内容"bin": {"hello": "hello.js"}
//package.json
{
"name": "hello",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {"hello": "hello.js"},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
5.执行命令npm link
;
期望结果
命令行输入hello可看到效果 ——————123;
实际结果
命令行输入hello
/Users/ymz/.nvm/versions/node/v8.9.4/bin/hello: line 1: use strict: command not found
/Users/ymz/.nvm/versions/node/v8.9.4/bin/hello: line 2: syntax error near unexpected token `'123''
/Users/ymz/.nvm/versions/node/v8.9.4/bin/hello: line 2: `console.log('123');'
请各路大神指正
在hello.js中第一行加入