作者:oko123 | 来源:互联网 | 2023-05-18 11:18
我有这行简单的代码:const target = e.target as HTMLLIElement;我收到此错误: Line 18:28: Parsing error: Missing semi
我有这行简单的代码:
const target = e.target as HTMLLIElement;
我收到此错误:
Line 18:28: Parsing error: Missing semicolon
> 18 | const target = e.target as HTMLLIElement;
| ^
我查看了几十个与我的问题类似的不同帖子,但没有一个与我的问题完全匹配,或者他们的解决方案与我的项目并不真正相关。例如,有些人遇到了 eslint 问题,但我没有安装 eslint 包。这是我的package.json
文件:
{
"name": "ally-autobot",
"version": "0.1.0",
"private": true,
"dependencies": {
"@craco/craco": "^6.1.1",
"@reduxjs/toolkit": "^1.5.1",
"@tailwindcss/postcss7-compat": "^2.1.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/lodash": "^4.14.168",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.7",
"@types/react-router-dom": "^5.1.7",
"autoprefixer": "^9",
"firebase": "^8.4.2",
"firebase-tools": "^9.10.0",
"lint": "^0.7.0",
"lodash-core": "^4.17.19",
"postcss": "^7",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-firebase-hooks": "^3.0.4",
"react-redux": "^7.2.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"redux-persist": "^6.0.0",
"source-map-loader": "^2.0.1",
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
"typescript": "~4.1.5"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
这是我的tsconfig.json
文件:
{
"compilerOptions": {
"sourceMap": true,
"incremental": true,
"target": "es5",
"module": "esnext",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
我也尝试过使用尖括号方法,但这不起作用,因为我在 tsx 文件中。我试过将 noImplicitAny 设置为 false。我尝试在与此错误相同的文件中为所有表达式添加分号。
关于如何解决这个问题的任何想法?
回答
应该是 eslint 的错误。
添加 eslintConfigpackage.json
可能会解决您的问题。以下设置是 create-react-app 中的默认 eslintConfig
"dependencies": {
...
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},