问题描述
我收到以下错误
Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is,add @babel/plugin-Syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
我已经尝试添加整个内容(第一个链接)和添加插件(第二个链接),效果很好,但尽管如此,我还是遇到了同样的错误。
这是我的json文件:
{
"name": "app2","version": "0.1.0","private": true,"dependencies": {
"@reduxjs/toolkit": "^1.5.1","@testing-library/jest-dom": "^4.2.4","@testing-library/react": "^9.5.0","@testing-library/user-event": "^7.2.1","firebase": "^8.4.2","firebase-tools": "^9.10.0","react": "^17.0.2","react-dom": "^17.0.2","react-redux": "^7.2.4","react-scripts": "4.0.3"
},"scripts": {
"start": "react-scripts start","build": "react-scripts build","test": "jest","eject": "react-scripts eject"
},"eslintConfig": {
"extends": "react-app"
},"browserslist": {
"production": [
">0.2%","not dead","not op_mini all"
],"development": [
"last 1 chrome version","last 1 firefox version","last 1 safari version"
]
},"description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app),using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template.","main": "index.js","devDependencies": {
"@babel/plugin-Syntax-jsx": "^7.12.13","@babel/plugin-transform-react-jsx": "^7.13.12","@babel/preset-react": "^7.13.13","jest": "^26.6.0"
},"keywords": [],"author": "","license": "ISC"
}
这是失败的测试文件:
const Login = require('./Login')
const { setActiveUser } = require('./userSlice')
test('login success',() =>{
expect(Login()).toBe(<button/>)
})
可能有什么问题?
编辑:我收到一条评论,告诉我要包含 babel 配置,我发现最接近的是 loadBabelConfij.js 文件:
'use strict';
Object.defineProperty(exports,'__esModule',{
value: true
});
Object.defineProperty(exports,'loadPartialConfig',{
enumerable: true,get: function () {
return _core().loadPartialConfig;
}
});
function _core() {
const data = require('@babel/core');
_core = function () {
return data;
};
return data;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)