简体   繁体   English

使用现有的 package.json 安装 jest

[英]Installing jest with an existing package.json

So I have a package.json file which I used on a different computer to run javascript tests.所以我有一个 package.json 文件,我在另一台计算机上使用它来运行 javascript 测试。 Now I have moved to another computer, I have the node_modules folder, package.json, package-lock.json and yarn.lock.现在我已经转移到另一台计算机,我有 node_modules 文件夹、package.json、package-lock.json 和 yarn.lock。 If I run npm install in the same folder where package.json is located, shouldn't jest also be installed?如果我在 package.json 所在的同一文件夹中运行 npm install ,不应该也安装 jest 吗? Since Jest is located in package.json.因为 Jest 位于 package.json 中。 If I run jest from the terminal I get command not found如果我从终端运行 jest 我找不到命令

To use an npm package from anywhere you need to have it installed globally like this:要从任何地方使用 npm 包,您需要像这样全局安装它:

npm install -g jest

An other solloution would be to add a new script in the package.json like this:另一种解决方案是在 package.json 中添加一个新脚本,如下所示:

scripts:{
   "jest":"jest"

}

And the type npm run jest和类型npm run jest

You can also have a look at this question : How to use package installed locally in node_modules?你也可以看看这个问题: How to use package installed in local in node_modules?

可能是因为您的项目的 node_modules/.bin 不在您的$PATH尝试添加它或运行./node_modules/.bin/jest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM