我目前正在学习如何设置一个使用 TypeScript 的 react-native-web,并且在 react-router-native 抛出错误时遇到错误:
当前未启用对实验性语法“classProperties”的支持。
检查 node_modules 文件夹并metro-react-native-babel-preset
添加@babel/plugin-proposal-class-properties
.
尝试将plugins
部分添加到babel
inpackage.json
但仍然出现错误:
"babel": {
"plugins": [
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
],
"presets": [
"module:metro-react-native-babel-preset"
]
}
这是我目前的设置
已安装的软件包package.json
:
{
"dependencies": {
"react": "16.8.6",
"react-dom": "16.8.6",
"react-native": "0.59.3",
"react-native-web": "0.11.2",
"react-router": "5.0.0",
"react-router-dom": "5.0.0",
"react-router-native": "5.0.0",
"react-scripts": "2.1.8"
},
"devDependencies": {
"@types/jest": "24.0.11",
"@types/react": "16.8.10",
"@types/react-native": "0.57.42",
"@types/react-router": "4.4.5",
"@types/react-router-dom": "4.3.2",
"@types/react-router-native": "4.2.4",
"@types/react-test-renderer": "16.8.1",
"babel-jest": "23.6.0",
"jest": "23.6.0",
"prettier": "1.16.4",
"react-art": "16.8.6",
"react-test-renderer": "16.8.6",
"ts-jest": "24.0.1",
"tslint": "5.15.0",
"tslint-config-prettier": "1.18.0",
"typescript": "3.4.1"
}
}
对于metro.config.js
:
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: true,
inlineRequires: true
}
})
}
};