如何解决在CRA打字稿环境中导出类型时如何解决解析错误
我使用CRA打字稿模板构建应用程序。
使用此代码时,存在解析错误。
export type { BaseModalProps } from "./BaseModalProps"
Parsing error: Declaration or statement expected
这些是我的package.json
和.eslintrc
的一部分
// package.json
"dependencies": {
"@craco/craco": "^5.6.4","@material-ui/core": "^4.11.0","@testing-library/jest-dom": "^4.2.4","@testing-library/react": "^9.3.2","@testing-library/user-event": "^7.1.2","@types/jest": "^24.0.0","@types/node": "^12.0.0","@types/react": "^16.9.0","@types/react-dom": "^16.9.0","axios": "^0.20.0","react": "^16.13.1","react-dom": "^16.13.1","react-facebook-login": "^4.1.1","react-google-login": "^5.1.21","react-hook-form": "^6.8.1","react-redux": "^7.2.1","react-router-dom": "^5.2.0","react-scripts": "3.4.1","redux": "^4.0.5","redux-logger": "^3.0.6","redux-persist": "^6.0.0","redux-saga": "^1.1.3","styled-components": "^5.1.1","styled-reset": "^4.2.1"
},"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"
]
},"devDependencies": {
"@types/react-facebook-login": "^4.1.2","@types/react-redux": "^7.1.9","@types/react-router-dom": "^5.1.5","@types/redux-logger": "^3.0.8","@types/styled-components": "^5.1.2","@typescript-eslint/eslint-plugin": "^4.1.0","@typescript-eslint/parser": "^4.1.0","craco-alias": "^2.1.1","eslint-config-airbnb": "^18.2.0","eslint-config-prettier": "^6.11.0","eslint-plugin-import": "^2.22.0","eslint-plugin-jsx-a11y": "^6.3.1","eslint-plugin-prettier": "^3.1.4","eslint-plugin-react": "^7.20.5","eslint-plugin-react-hooks": "^4.0.8","husky": ">=4","lint-staged": ">=10","prettier": "^2.1.1","typescript": "^4.0.2"
},
// .eslintrc
"env": {
"browser": true,"es2020": true
},"parser": "@typescript-eslint/parser","plugins": ["@typescript-eslint","react"],"extends": [
"plugin:react/recommended","airbnb","prettier/react","plugin:prettier/recommended","plugin:@typescript-eslint/recommended"
],"parserOptions": {
"ecmaFeatures": {
"jsx": true,"tsx": true,"ts": true,"d.ts": true
},"ecmaVersion": 11,"sourceType": "module"
},
我该如何解决?
解决方法
这归因于语法错误。 您要导入还是导出? 如果要导入,应该是
import { BaseModalProps } from "./BaseModalProps"
如果要导出:
export { BaseModalProps };
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。