TypeScript TSC在项目配置上非常慢,最终失败,

ggazkfy8  于 4个月前  发布在  TypeScript
关注(0)|答案(8)|浏览(53)

Bug报告

🔎 搜索词

TSC,慢速,内存不足

🕗 版本与回归信息

Typescript版本4.9.3
Windows 11操作系统

  • 这是一次崩溃

💻 代码

package.json

{
  "name": "client",
  "version": "0.1.0",
  "proxy": "http://localhost:5000",
  "private": true,
  "type": "module",
  "dependencies": {
    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@fortawesome/fontawesome-svg-core": "^6.2.1",
    "@fortawesome/free-solid-svg-icons": "^6.2.1",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "@kasparund/kasparund_enums": "^0.0.148",
    "@material/react-chips": "^0.15.0",
    "@mui/icons-material": "^5.10.9",
    "@mui/lab": "^5.0.0-alpha.107",
    "@mui/material": "^5.10.13",
    "@mui/styles": "^5.10.10",
    "@mui/x-date-pickers": "^5.0.8",
    "@react-google-maps/api": "^2.1.1",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^7.1.2",
    "@types/history": "^5.0.0",
    "@types/jest": "^27.4.1",
    "@types/node": "^17.0.21",
    "@types/prop-types": "^15.7.5",
    "@types/react": "^18.0.24",
    "@types/react-dom": "^18.0.8",
    "@types/react-redux": "^7.1.24",
    "@types/react-router": "^5.1.19",
    "@wojtekmaj/react-daterange-picker": "^3.4.0",
    "add": "^2.0.6",
    "apexcharts": "^3.35.5",
    "base64url": "^3.0.1",
    "blueimp-md5": "^2.18.0",
    "chart.js": "^2.9.4",
    "classnames": "^2.3.1",
    "clsx": "^1.1.1",
    "connected-react-router": "^6.9.1",
    "country-data": "^0.0.31",
    "customize-cra": "^1.0.0",
    "dayjs": "^1.11.6",
    "decimal.js": "^10.3.1",
    "dotenv": "^8.2.0",
    "final-form": "^4.20.7",
    "final-form-material-ui": "^0.3.0",
    "google-map-react": "^2.1.9",
    "history": "^4.10.1",
    "jsdom": "^20.0.2",
    "jwt-decode": "^3.1.2",
    "lodash": "^4.17.21",
    "lodash.debounce": "^4.0.8",
    "moment": "^2.29.4",
    "oidc-client": "^1.11.5",
    "query-string": "^7.1.1",
    "ra-data-simple-rest": "^3.13.4",
    "ra-tree-menu": "^1.0.0",
    "react": "18",
    "react-admin": "4.6.0",
    "react-apexcharts": "^1.3.9",
    "react-app-rewired": "^2.1.8",
    "react-avatar": "^3.10.0",
    "react-chartjs-2": "^2.11.1",
    "react-circular-progressbar": "^2.0.4",
    "react-confirm-alert": "^3.0.6",
    "react-copy-button": "^0.2.3",
    "react-country-flag": "^3.0.2",
    "react-csv": "^2.0.3",
    "react-csv-downloader": "^2.2.0",
    "react-datetime-picker": "^3.2.0",
    "react-day-picker": "^8.3.6",
    "react-dom": "18",
    "react-file-viewer": "^1.2.1",
    "react-final-form": "^6.5.9",
    "react-helmet": "^6.1.0",
    "react-icons": "^4.2.0",
    "react-json-view": "^1.21.3",
    "react-loading": "^2.0.3",
    "react-moment": "^1.1.1",
    "react-pdf": "^5.2.0",
    "react-perfect-scrollbar": "^1.5.8",
    "react-query": "^3.39.2",
    "react-router-dom": "^6.4.3",
    "react-select": "^5.6.1",
    "react-swipeable-views": "^0.14.0",
    "react-use-draggable-scroll": "^0.4.7",
    "validator": "^13.7.0",
    "yarn": "^1.22.17"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build",
    "serve": "vite preview",
    "lint": "eslint --ext .js,.jsx,.ts,.tsx src --color",
    "format": "prettier --write 'src/**/*.{ts,tsx,scss,css,json}'",
    "typecheck": "tsc --project './tsconfig.json'",
    "typecheck-build": "tsc -b --verbose",
    "watch": "tsc --watch --noEmit --project './tsconfig.json'",
    "test": "vitest",
    "coverage": "vitest run --coverage"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "plugin:prettier/recommended"
    ],
    "env": {
      "browser": true,
      "node": true
    }
  },
  "prettier": {
    "printWidth": 100,
    "bracketSpacing": true,
    "trailingComma": "es5",
    "semi": false,
    "singleQuote": true,
    "tabWidth": 2
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.+(js|jsx|ts|tsx)": [
      "eslint --fix",
      "git add"
    ],
    "*.+(ts|tsx|scss|css|json)": [
      "prettier --write",
      "git add"
    ]
  },
  "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/chart.js": "^2.9.35",
    "@types/react-helmet": "^6.1.5",
    "@types/react-router-dom": "^5.3.3",
    "@typescript-eslint/eslint-plugin": "^5.38.0",
    "@typescript-eslint/parser": "^5.21.0",
    "@vitejs/plugin-react": "^2.2.0",
    "@vitest/coverage-c8": "^0.25.1",
    "babel-eslint": "^10.1.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-config-react-app": "^7.0.1",
    "eslint-import-resolver-typescript": "^2.7.1",
    "eslint-plugin-flowtype": "^8.0.3",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-jest": "^26.1.5",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.29.4",
    "eslint-plugin-react-hooks": "^4.5.0",
    "eslint-plugin-unused-imports": "^2.0.0",
    "eslint-webpack-plugin": "^3.1.1",
    "husky": "^8.0.2",
    "lint-staged": "^12.4.1",
    "prettier": "^2.6.2",
    "prettier-eslint": "^14.0.1",
    "prettier-eslint-cli": "^5.0.1",
    "source-map-loader": "^3.0.1",
    "ts-loader": "^9.2.7",
    "typescript": "^4.9.3",
    "vite": "^3.2.3",
    "vite-tsconfig-paths": "^3.5.2",
    "vitest": "^0.25.1"
  },
  "resolutions": {
    "//": "See https://github.com/facebook/create-react-app/issues/11773, can be removed once we switch to react-scripts v5",
    "react-error-overlay": "6.0.9"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["dom", "dom.iterable", "esnext"],
    "types": ["vite/client", "vitest/globals"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": false,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "rootDir": "./src",
    "baseUrl": "./src"
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "coverage", "artifacts", "public"]
}

🙁 实际行为

我使用 yarn typecheck,它只是运行 tsc --project './tsconfig.json'。大约一个小时后,我遇到了一次内存不足的崩溃:

$ yarn typecheck
yarn run v1.22.5
$ tsc --project './tsconfig.json'

<--- Last few GCs --->

[10320:000001B789ABB6C0]  1504038 ms: Mark-sweep 4034.6 (4129.2) -> 4018.9 (4128.4) MB, 1549.7 / 0.0 ms  (average mu = 0.205, current mu = 0.003) allocation failure; scavenge might not succeed
[10320:000001B789ABB6C0]  1505584 ms: Mark-sweep 4034.6 (4128.4) -> 4018.9 (4128.4) MB, 1535.6 / 0.0 ms  (average mu = 0.115, current mu = 0.007) allocation failure; scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF75CF51B7F node_api_throw_syntax_error+203775
 2: 00007FF75CED1556 v8::internal::wasm::WasmCode::safepoint_table_offset+63558
 3: 00007FF75CED28C2 v8::internal::wasm::WasmCode::safepoint_table_offset+68530
 4: 00007FF75D9747F4 v8::Isolate::ReportExternalAllocationLimitReached+116
 5: 00007FF75D95FB52 v8::Isolate::Exit+674
 6: 00007FF75D7E1BBC v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124
 7: 00007FF75D7EEE9D v8::internal::Heap::PublishPendingAllocations+1117
 8: 00007FF75D7EBF27 v8::internal::Heap::PageFlagsAreConsistent+3367
 9: 00007FF75D7DE657 v8::internal::Heap::CollectGarbage+2039
10: 00007FF75D7F5013 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099
11: 00007FF75D7F58BD v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93
12: 00007FF75D8050F3 v8::internal::Factory::NewFillerObject+851
13: 00007FF75D4F6825 v8::internal::DateCache::Weekday+1349
14: 00007FF75DA11E81 v8::internal::SetupIsolateDelegate::SetupHeap+558193
15: 00007FF6DE4F97C6
error Command failed with exit code 134.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

🙂 预期行为

tsc 在几秒钟内成功运行。

chhqkbe1

chhqkbe11#

src的内容是什么?

tjrkku2a

tjrkku2a2#

src的内容是什么?
一个基本的React应用。这里是src的统计信息:

总结

总数:359个文件,26586行代码,232条注解,2415个空白行,总共29233行

语言

语言文件数代码行数注解数空白行数总行数
TypeScript React22123,5741512,02025,745
TypeScript1342,919793813,379
CSS493214109
6l7fqoea

6l7fqoea3#

看起来很正常;这最多只需要几秒钟。在少数文件中可能有一些非常奇怪的事情导致了崩溃。如果你能缩小范围,将可以发布的文件列出来,我们可以进行调查,但就目前而言,如果没有具体的重现步骤,我们无法做太多事情。

8e2ybdfx

8e2ybdfx4#

感谢您的回复。这只是一个基本的应用。但是,是否有一些我可以用我的设置测试的TypeScript项目示例?

aurhwmvo

aurhwmvo5#

@sebastianbuechler 我正在经历相同的问题,你找到了任何解决方案吗?

uqdfh47h

uqdfh47h6#

@sebastianbuechler 我正在经历相同的问题,你找到任何解决方案了吗?
没有。问题仍然存在。

6g8kf2rb

6g8kf2rb7#

我正在经历这个问题,在5.0.2版本中。

7kjnsjlb

7kjnsjlb8#

我正在经历这个问题,在5.0.2版本中。

<--- Last few GCs --->
[34264:000001F47698B860]   168464 ms: Mark-sweep 4060.7 (4130.5) -> 4045.5 (4131.2) MB, 1295.8 / 0.0 ms  (average mu = 0.136, current mu = 0.018) allocation failure scavenge might not succeed
[34264:000001F47698B860]   169700 ms: Mark-sweep 4061.4 (4131.2) -> 4046.3 (4132.0) MB, 1211.7 / 0.0 ms  (average mu = 0.083, current mu = 0.020) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF722AB815F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+114079
 2: 00007FF722A454C6 DSA_meth_get_flags+65542
 3: 00007FF722A4637D node::OnFatalError+301
 4: 00007FF72337BA0E v8::Isolate::ReportExternalAllocationLimitReached+94  
 5: 00007FF723365FED v8::SharedArrayBuffer::Externalize+781
 6: 00007FF7232093BC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
 7: 00007FF723216069 v8::internal::Heap::PublishPendingAllocations+1129
 8: 00007FF72321303A v8::internal::Heap::PageFlagsAreConsistent+2842       
 9: 00007FF723205C99 v8::internal::Heap::CollectGarbage+2137
10: 00007FF723203E50 v8::internal::Heap::AllocateExternalBackingStore+2000 
11: 00007FF7232289D6 v8::internal::공장::NewFillerObject+214
12: 00007FF722F5AEA5 v8::internal::DateCache::Weekday+1797
13: 00007FF723409701 v8::internal::SetupIsolateDelegate::SetupHeap+494417  
14: 00007FF72340A6D3 v8::internal::SetupIsolateDelegate::SetupHeap+498467  
15: 000001F40077C29B

就我的情况而言,当我将skipLibCheck false 修改为 true 时,问题得到了解决。

{
  "compilerOptions": {
    "skipLibCheck": true
  }
}

相关问题