npm ERR! code ENOENT npm ERR! syscall open npm ERR! path E:\jd\pro1\ka-mrm-jd_intern\package.json np

描述:

做jest测试的时候遇到执行npm test报错

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path E:\jd\pro1\ka-mrm-jd_intern\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'E:\jd\pro1\ka-mrm-jd_intern\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\limengdong\AppData\Roaming\npm-cache\_logs\2019-12-31T07_44_19_600Z-debug.log

发现npm install --save-dev jest 命令执行完的是带有个package后缀的json在这里插入图片描述

把package的后缀去掉即可
在这里插入图片描述
如果出现其他的上述的npm ERROR 均会报这个错,所以如果不是这个原因还需具体排查

附上Jest的安装流程

安装命令

//cmd进入到相应的文件夹中,执行下面代码
npm install --save-dev jest

更改package.json 保证文件名一致,编辑文件内容

{
    
    
  "scripts": {
    
    
    "test": "jest"
  }
}

创建js文件

//sum.js

function sum(a, b) {
    
    
  return a + b;
}
module.exports = sum;
//sum.test.js

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
    
    
  expect(sum(1, 2)).toBe(3);
});

执行

npm test

猜你喜欢

转载自blog.csdn.net/Python_BT/article/details/109101108