嗨,我遇到了
simplifica/App.jsx: Unexpected token (17:8)
15 |
16 | export default class App extends React.Component {
> 17 | state = {
| ^
18 | isLoadingComplete: false
19 | };
20 |
在开玩笑的时候,我花了很多时间,我发现了一些类似我的问题,但是这些解决方案对我来说都行不通,都不使用@ babel / plugin-proposal-classproperties
这是我的babel.config.js
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo', 'module:react-native-dotenv'],
plugins: [
[
'@babel/plugin-proposal-decorators',
{
legacy: true
}
],
['@babel/plugin-proposal-class-properties', { loose: true }]
]
};
};
这是我的jest config
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|react-clone-referenced-element|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|sentry-expo|native-base))"
],
"moduleFileExtensions": [
"js",
"jsx"
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.jsx$": "babel-jest",
".*": "<rootDir>/node_modules/webpack-babel-jest"
}
}
答案 0 :(得分:0)
解决了!对于有相同问题的任何人:
"^.+\\.js$": "babel-jest",
"^.+\\.jsx$": "babel-jest",
应该只有一个,像这样:
"^.+\\.(js|jsx|ts)$": "babel-jest"