如何解决添加了 babel/present-react 但错误仍然存在
我收到以下错误
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 举报,一经查实,本站将立刻删除。