我正在尝试编译我的 React Native 应用程序,但出现以下错误:
SyntaxError:C:\Users\Ori\Desktop\Projects\React\my-app\node_modules@react-native-community\google-signin\src\GoogleSignin.js:目前未启用对实验语法“classProperties”的支持(8:16)
将 @babel/plugin-proposal-class-properties ( https://git.io/vb4SL ) 添加到 Babel 配置的“插件”部分以启用转换。
如果我理解正确,因为它是一个 react native 应用程序,.babelrc 文件被忽略,但仍有一些方法可以克服它。我在网上看到了一些解决方案,但似乎没有一个对我有用。
我试过了:
- 在与 package.json 相同的文件夹中添加 babel.config.js:
module.exports = {
presets: [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript'
],
plugins: [
'@babel/plugin-proposal-class-properties'
]
};
- 将 babel 配置添加到 package.json
{
presets: [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript'
],
plugins: [
'@babel/plugin-proposal-class-properties'
]
}
- 向插件添加松散属性:
"plugins": [
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
似乎没有任何效果。
我的代码:
包.json:
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.5.0",
"@material-ui/icons": "^4.4.3",
"@react-native-community/google-signin": "^3.0.1",
"jquery": "^3.4.1",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-ga": "^2.7.0",
"react-native-google-signin": "^2.1.0",
"react-scripts": "3.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"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"
]
},
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-class-properties": "^7.5.5"
}
}
babel.config.js:
module.exports = {
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-regenerator',
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
},
],
],
presets: [
"@babel/preset-flow",
'module:metro-react-native-babel-preset',
],
};
如果有人能说明这个问题,那就太好了,谢谢!