tsc 不忽略带有 "skipLibCheck" 的 lib 文件:true

tsc not ignoring lib files with "skipLibCheck": true

对于这个项目,我有一个带有 2 个工作区(api 和 frontEnd)的 monorepo。我最近将节点从 V10 升级到 V16,迁移几乎完成。我可以在本地 运行,但无法再构建。

当我运行yarn workspace api start:dev,在api/package.json中定义为"start:dev": "cross-env NODE_ENV=development npx ts-node-dev -r dotenv/config -r tsconfig-paths/register --respawn --transpile-only src/index.ts"时,在localhost上运行很顺利。

当我 运行 yarn workspace api build:ts, 在 api/package.json 中定义为 yarn run tsc 时,我得到以下类型的错误(我只保留了 1每个文件的错误以遵守问题字符限制,但有超过 2000 行):

../node_modules/@types/babel__traverse/index.d.ts(68,50): error TS1005: ']' expected.
../node_modules/@types/express-serve-static-core/index.d.ts(99,68): error TS1110: Type expected.
../node_modules/@types/node/assert.d.ts(12,72): error TS1144: '{' or ';' expected.
../node_modules/@types/node/index.d.ts(72,1): error TS1084: Invalid 'reference' directive syntax.
../node_modules/@types/sinon/index.d.ts(30,54): error TS1005: ',' expected.
../node_modules/express-validator/src/chain/validators-impl.d.ts(79,27): error TS1005: ',' expected.
../node_modules/express-validator/src/chain/validators.d.ts(66,27): error TS1005: ',' expected.
../node_modules/express-validator/src/validation-result.d.ts(13,64): error TS1005: ',' expected.

这是我的api/tsconfig.json:

    {
      "compilerOptions": {
        "lib": ["es6"],
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "outDir": "./build",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": true,
        "skipLibCheck": true,
        "baseUrl": "./src",
        "paths": {
          "@/*": ["./*"]
        }
      },
      "include": ["src/**/*"],
      "exclude": [
        "**/node_modules/*",
        "node_modules",
        "**/*.test.ts",
        "**/test/**/*"
      ]
    }

这是我的 api/package.json:

    {
      "name": "api",
      "version": "3.8.18",
      "description": "",
      "license": "NONE",
      "private": true,
      "nohoist": [
        "**/express*",
        "**/express*/**"
      ],
      "engines": {},
      "scripts": {
        "build:ts": "yarn run tsc",
        "start": "yarn run start:prod",
        "start:prod": "cross-env NODE_ENV=production node -r ./tsconfig-paths-bootstrap.js build/index.js",
        "start:dev": "cross-env NODE_ENV=development npx ts-node-dev -r dotenv/config -r tsconfig-paths/register --respawn --transpile-only src/index.ts",
        "test": "cross-env  NODE_ENV=test mocha 'test/**/*.test.ts' --timeout 60000 --recursive --no-deprecation -r ts-node/register -r tsconfig-paths/register --file test/testUtils/test-setup.ts ",
        "test:unit": "yarn run test --grep @unit",
        "test:integration": "yarn run test --grep @int",
        "typeorm:cli": "ts-node -r tsconfig-paths/register ../node_modules/typeorm/cli -f ./src/ormconfig.ts",
        "migration:generate": "yarn run typeorm:cli migration:generate -n",
        "migration:create": "yarn run typeorm:cli migration:create -n",
        "migration:run": "yarn run typeorm:cli migration:run",
        "migration:revert": "yarn run typeorm:cli migration:revert",
        "migration:show": "yarn run typeorm:cli migration:show"
      },
      "devDependencies": {
        "@types/chai": "^4.3.0",
        "@types/chai-as-promised": "^7.1.4",
        "@types/cors": "^2.8.12",
        "@types/express": "^4.17.13",
        "@types/mocha": "^9.1.0",
        "@types/morgan": "^1.9.3",
        "@types/node": "^17.0.15",
        "@types/node-fetch": "^3.0.2",
        "@types/sinon": "^10.0.10",
        "@types/sinon-chai": "^3.2.8",
        "chai": "^4.3.6",
        "chai-as-promised": "^7.1.1",
        "dotenv": "^16.0.0",
        "mocha": "^9.2.0",
        "sinon": "^13.0.1",
        "sinon-chai": "^3.7.0",
        "sinon-express-mock": "^2.2.1",
        "supertest": "^6.2.2",
        "ts-node": "10.4.0",
        "ts-node-dev": "^1.1.8",
        "tsconfig-paths": "^3.12.0",
        "typescript": "^4.5.5"
      },
      "dependencies": {
        "@typescript-eslint/eslint-plugin": "^5.10.2",
        "@typescript-eslint/parser": "^5.10.2",
        "async-exit-hook": "^2.0.1",
        "aws-sdk": "^2.1069.0",
        "axios": "^0.25.0",
        "babel-plugin-module-resolver": "^4.1.0",
        "body-parser": "^1.19.1",
        "cors": "^2.8.5",
        "cross-env": "^7.0.3",
        "crypto-js": "^4.1.1",
        "eslint-import-resolver-node": "^0.3.2",
        "eslint-plugin-import": "^2.14.0",
        "eslint-plugin-jsx-a11y": "6.x",
        "eslint-plugin-react": "7.x",
        "express": "^4.17.2",
        "express-jwt": "^6.1.0",
        "express-jwt-authz": "^2.4.1",
        "express-query-boolean": "^2.0.0",
        "express-validator": "^6.14.0",
        "jwks-rsa": "^2.0.5",
        "morgan": "^1.10.0",
        "morgan-json": "^1.1.0",
        "node-fetch": "^3.2.0",
        "pg": "^8.7.3",
        "prettier": "^2.5.1",
        "redis": "^4.0.3",
        "sinon": "^13.0.1",
        "slugify": "^1.6.5",
        "tsconfig-paths": "^3.12.0",
        "tspath": "^1.3.7",
        "typeorm": "^0.2.41",
        "winston": "^3.5.1",
        "winston-daily-rotate-file": "^4.6.0"
      }
    }

我试过的

../node_modules/@types/express-serve-static-core/index.d.ts(99,68): error TS1110: Type expected.
../node_modules/@types/node/assert.d.ts(12,72): error TS1144: '{' or ';' expected.
../node_modules/@types/node/index.d.ts(72,1): error TS1084: Invalid 'reference' directive syntax.
../node_modules/express-validator/src/chain/validators-impl.d.ts(79,27): error TS1005: ',' expected.

版本打印输出

nvm v 1.1.8.

nvm current v16.13.2

yarn -v 1.22.18

yarn run tsc --version 版本 2.9.2

感谢您的帮助!

我找到了罪魁祸首。这是“tspath”依赖项。

为了删除它,我执行了“yarn workspace api remove tspath”。