【发布时间】:2026-01-04 17:10:02
【问题描述】:
也许你可以帮助我? 我尝试将 jest 配置为使用 babel@7 所以我有:
"jest": "^23.4.1",
"@babel/core": "^7.0.0-beta.54",
"babel-7-jest": "^21.3.3",
"babel-jest": "^20.0.3",
并且在 package.json 中开玩笑配置
"jest": {
"transform": {
"^.+\\.js$": "babel-7-jest",
},
得到了
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
但是如果我使用
"jest": {
"transform": {
"^.+\\.js$": "babel-jest",
},
我明白了
Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
babel 配置:https://gist.github.com/SilentImp/1506e9c26d16d9839a4469c6f3ae5c4d
也许你有一些想法?
【问题讨论】:
-
我也明白了。围绕此问题的开放 GitHub 问题越来越多,Jest 团队正在采取防御措施并避免提供有效的解决方案来解决此问题。
-
听到这个消息有点难过
-
查看我的答案,我已经为我的项目解决了这个问题。希望它也适合你!
标签: babeljs jestjs babel-jest babel-core