【发布时间】:2020-01-09 14:17:00
【问题描述】:
我有一个根据本教程设置的 monorepo:tutorial。
这个项目由一个主文件夹(series4)组成,其中包含三个包,分别专注于 web、移动应用程序和公共代码——它们分别被命名为 web、app 和 common 文件夹。
总结...这些文件夹是:
/series4/packages/web
/series4/packages/common
/series4/packages/app
我正在尝试使用 Modal 模块,但出现此错误:
语法错误:series4/node_modules/react-native-modal/src/index.js: 目前不支持实验性语法“classProperties” 启用 (25:20)
我已阅读此处的文档:Babel。
但是我无法解决这个错误。
“series4”目录下的package.json是:
{
"name": "@wow/common",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "rimraf dist && tsc",
"watch": "tsc --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "16.8.2",
"react-native": "0.59.0-rc.1",
"react-native-elements": "^1.1.0",
"react-native-image-slider-box": "^1.0.5",
"react-native-snap-carousel": "^3.8.0"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@types/react-native": "0.57.36",
"rimraf": "^2.6.3",
"typescript": "3.3.3"
}
}
babel.config.js 文件(在 series4 目录下)是:
module.exports = {
presets: [
"@babel/preset-env",
"@babel/preset-react"
],
plugins: [
'@babel/proposal-class-properties',
'@babel/plugin-proposal-class-properties'
],
babelrcRoots: [
".",
"packages/*",
],
};
我在 web 和 common 文件夹中配置了以下 babelrc。
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
[
"@babel/plugin-proposal-class-properties"
]
]
}
common 文件夹下的 package.json 为:
{
"name": "@wow/common",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "rimraf dist && tsc",
"watch": "tsc --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "16.8.2",
"react-native": "0.59.0-rc.1",
"react-native-elements": "^1.1.0",
"react-native-image-slider-box": "^1.0.5",
"react-native-snap-carousel": "^3.8.0"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@types/react-native": "0.57.36",
"rimraf": "^2.6.3",
"typescript": "3.3.3"
}
}
web文件夹中的package.json是:
{
"name": "react-native-web-workout-series",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "24.0.5",
"@types/node": "11.9.4",
"@types/react": "16.8.3",
"@types/react-dom": "16.8.1",
"@wow/common": "1.0.0",
"react": "^16.8.2",
"react-art": "16.8.2",
"react-dom": "^16.8.2",
"react-native": "0.55.4",
"react-native-modal": "^11.3.1",
"react-native-web": "0.10.0",
"react-scripts": "2.1.5",
"typescript": "3.3.3"
},
"scripts": {
"start": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@types/react-native": "0.55.4",
"babel-plugin-module-resolver": "^3.2.0",
"cross-env": "^5.2.0"
}
}
运行时出现错误
yarn start
web 文件夹中的命令(当我在没有 Modal 模块的情况下执行该命令时,该命令可以完美运行)。
我错过了什么?
【问题讨论】:
标签: javascript react-native babeljs yarnpkg