webpack 我想用typescript重写我的项目,但是App.tsx文件中有一个问题

enxuqcxy  于 2023-11-19  发布在  Webpack
关注(0)|答案(1)|浏览(161)

我在编译我的App.tsx时自动创建的App.js文件中出现ESLint错误,其中包含一个简单的组件。如何解决这个问题?有一个错误示例:
[eslint]
src/App.js
第1行:1:在模块中不需要“use strict”
第1行:1:字符串必须使用单引号
App.tsx:

  1. export default function App() { return <div>it works!</div> }

字符串
tsconfig.json:

  1. {
  2. "compilerOptions": {
  3. "target": "es2016",
  4. "module": "commonjs",
  5. "esModuleInterop": true,
  6. "forceConsistentCasingInFileNames": true,
  7. "strict": true,
  8. "skipLibCheck": true,
  9. "jsx": "react-jsx"
  10. },
  11. "include": ["src", "src/@types"]
  12. }


package.json:

  1. {
  2. "name": "my_gallery",
  3. "version": "0.1.0",
  4. "private": true,
  5. "dependencies": {
  6. "@fortawesome/fontawesome-svg-core": "^6.4.2",
  7. "@fortawesome/free-brands-svg-icons": "^6.4.2",
  8. "@fortawesome/free-regular-svg-icons": "^6.4.2",
  9. "@fortawesome/free-solid-svg-icons": "^6.4.2",
  10. "@fortawesome/react-fontawesome": "^0.2.0",
  11. "@reduxjs/toolkit": "^1.9.7",
  12. "@tanstack/react-query": "^4.36.1",
  13. "@testing-library/jest-dom": "^5.17.0",
  14. "@testing-library/react": "^13.4.0",
  15. "@testing-library/user-event": "^13.5.0",
  16. "axios": "^1.5.1",
  17. "eslint-config-airbnb-typescript": "^17.1.0",
  18. "react": "^18.2.0",
  19. "react-dom": "^18.2.0",
  20. "react-paginate": "^8.2.0",
  21. "react-redux": "^8.1.3",
  22. "react-router-dom": "^6.16.0",
  23. "react-scripts": "5.0.1",
  24. "react-select": "^5.7.7",
  25. "web-vitals": "^2.1.4"
  26. },
  27. "scripts": {
  28. "start": "react-scripts start",
  29. "build": "react-scripts build",
  30. "test": "react-scripts test",
  31. "eject": "react-scripts eject"
  32. },
  33. "eslintConfig": {
  34. "extends": [
  35. "react-app",
  36. "react-app/jest"
  37. ]
  38. },
  39. "browserslist": {
  40. "production": [
  41. ">0.2%",
  42. "not dead",
  43. "not op_mini all"
  44. ],
  45. "development": [
  46. "last 1 chrome version",
  47. "last 1 firefox version",
  48. "last 1 safari version"
  49. ]
  50. },
  51. "devDependencies": {
  52. "@babel/eslint-parser": "^7.22.15",
  53. "@types/jest": "^29.5.6",
  54. "@types/node": "^20.8.8",
  55. "@types/react": "^18.2.31",
  56. "@types/react-dom": "^18.2.14",
  57. "eslint": "^8.52.0",
  58. "eslint-config-airbnb": "^19.0.4",
  59. "eslint-plugin-import": "^2.29.0",
  60. "eslint-plugin-jsx-a11y": "^6.7.1",
  61. "eslint-plugin-react": "^7.33.2",
  62. "typescript": "^5.2.2"
  63. }
  64. }

yfjy0ee7

yfjy0ee71#

设置你的tsconfig.json到这个,它应该解决你的问题

  1. {
  2. "compilerOptions": {
  3. "target": "ES6",
  4. "module": "ESNext",
  5. "jsx": "react",
  6. "strict": true,
  7. "esModuleInterop": true,
  8. "moduleResolution":"node",
  9. },
  10. "moduleResolution":"node",
  11. }

字符串

相关问题