npx 可以调用项目内部安装的模块。
{
"name": "jest-example",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "jest",
},
"author": "",
"license": "ISC",
"dependencies": {
"jest": "^27.3.1"
},
"devDependencies": {
},
"description": ""
}
例如,看这个项目的package.json文件,在命令行输入 npm run test
,实际调用的是 npm run jest
。
但是如果直接在命令行输入 jest
就会报错:“zsh: command not found: jest。
想要在命令行调用,需要这样输入 :npx jest
npx 还有其他的功能,比如,避免全局安装模块、使用低版本的模块…,目前还没用到,就不写了!