问题
jest运行测试用例,使用到了typeof
关键字,报错如下
RangeError: Maximum call stack size exceeded at _typeof
问题所在
排查发现,原来是babel的问题
解决
替换依赖后就可以
1、修改 package.json 依赖
修改前
{ "type": "module", "scripts": { "test": "jest --verbose" }, "devDependencies": { "jest": "^29.3.1", "babel-jest": "^29.3.1", "babel-core": "^6.26.3", "babel-preset-env": "^1.7.0", "regenerator-runtime": "^0.13.11" } }
修改后
{ "type": "module", "scripts": { "test": "jest --verbose" }, "devDependencies": { "@babel/core": "^7.20.2", "@babel/preset-env": "^7.20.2", "babel-jest": "^29.3.1", "jest": "^29.3.1" } }
2、.babelrc修改如下
修改前
{ "presets": ["env"] }
修改后
{ "presets": [ [ "@babel/preset-env", { "targets": { "node": "current" } } ] ] }
参考