在 node_modules/jest-diff/build/diffLines.d.ts 中构建 React + Typescript 错误

Jib*_*b'z 6 typescript reactjs jestjs

我目前正在开发一个使用 React 和 Typescript 的项目,该项目运行良好,直到最近使用 Jenkins 构建时发生以下错误(并且该错误也出现在我的计算机上的 intellij 中)。似乎是一个模块作为编译错误。

[INFO] Creating an optimized production build...
[INFO] Failed to compile.
[INFO] 
[INFO] /jenkins/workspace/project/front/node_modules/jest-diff/build/diffLines.d.ts
[INFO] TypeScript error in /jenkins/workspace/project/front/node_modules/jest-diff/build/diffLines.d.ts(8,13):
[INFO] '=' expected.  TS1005
[INFO] 
[INFO]      6 |  */
[INFO]      7 | import { Diff } from './cleanupSemantic';
[INFO]   >  8 | import type { DiffOptions } from './types';
[INFO]        |             ^
[INFO]      9 | export declare const diffLinesUnified: (aLines: string[], bLines: string[], options?: DiffOptions | undefined) => string;
[INFO]     10 | export declare const diffLinesUnified2: (aLinesDisplay: string[], bLinesDisplay: string[], aLinesCompare: string[], bLinesCompare: string[], options?: DiffOptions | undefined) => string;
[INFO]     11 | export declare const diffLinesRaw: (aLines: string[], bLines: string[]) => Diff[];
Run Code Online (Sandbox Code Playgroud)

我在这里有点迷茫,所以有人有解决这个问题的线索吗?提前致谢。

这是我的 package.json 文件

{
  "name": "front",
  "version": "1.0.0-SNAPSHOT",
  "private": true,
  "homepage": "./",
  "dependencies": {
    "@types/echarts": "4.1.11",
    "@types/jest": "24.0.15",
    "@types/node": "12.6.3",
    "@types/react": "16.8.23",
    "@types/react-dom": "16.8.4",
    "antd": "3.20.3",
    "axios": "0.19.0",
    "classnames": "2.2.6",
    "connected-react-router": "6.3.1",
    "css-element-queries": "1.2.1",
    "echarts": "4.2.1",
    "jsonwebtoken": "8.5.1",
    "rc-texty": "0.2.0",
    "rc-tween-one": "2.6.3",
    "react": "16.8.6",
    "react-compound-slider": "2.2.0",
    "react-dom": "16.8.6",
    "react-redux": "7.1.0",
    "react-router": "4.4.0-beta.7",
    "react-router-config": "5.0.0",
    "react-router-dom": "4.4.0-beta.7",
    "react-scripts": "3.3.0",
    "redux": "4.0.4",
    "redux-logger": "3.0.6",
    "reflect-metadata": "0.1.13",
    "tailwindcss": "1.1.2",
    "typescript": "3.5.3"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test --env=jsdom --watchAll=false",
    "test:watch": "react-app-rewired test --env=jsdom",
    "lint:ts": "eslint ./src/**/*.{ts,tsx}",
    "lint:ts:errors": "eslint ./src/**/*.{ts,tsx} --quiet",
    "lint:ts:fix": "eslint ./src/**/*.{ts,tsx} --fix",
    "madge": "madge --circular --extensions ts ./src/",
    "lint:scss": "stylelint ./src/**/*.scss --syntax scss",
    "lint:scss:fix": "stylelint ./src/**/*.scss --syntax scss --fix"
  },
  "lint-staged": {
    "*.ts": "npm run lint:ts:errors",
    "*.tsx": "npm run lint:ts:errors"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "jest": {
    "moduleNameMapper": {
      "^@/(.*)$": "<rootDir>/src/$1"
    }
  },
  "browserslist": [
    ">0.2%",
    "ie 11"
  ],
  "devDependencies": {
    "@babel/parser": "7.5.0",
    "@types/classnames": "2.2.9",
    "@types/enzyme": "3.9.1",
    "@types/enzyme-adapter-react-16": "1.0.5",
    "@types/file-saver": "2.0.1",
    "@types/jsonwebtoken": "8.3.2",
    "@types/react-redux": "7.1.1",
    "@types/react-router": "4.4.4",
    "@types/react-router-config": "1.1.2",
    "@types/react-router-dom": "4.3.1",
    "@types/redux-logger": "3.0.7",
    "awesome-typescript-loader": "5.2.1",
    "babel-plugin-import": "1.11.0",
    "cross-env": "5.2.0",
    "customize-cra": "0.2.12",
    "enzyme": "3.9.0",
    "enzyme-adapter-react-16": "1.12.1",
    "file-saver": "2.0.1",
    "husky": "3.0.5",
    "jest-enzyme": "7.0.2",
    "less": "3.9.0",
    "less-loader": "5.0.0",
    "lint-staged": "9.2.5",
    "madge": "3.4.4",
    "node-sass": "4.12.0",
    "prettier": "1.18.2",
    "react-app-polyfill": "1.0.1",
    "react-app-rewire-postcss": "3.0.2",
    "react-app-rewired": "2.1.3",
    "scss-to-json": "2.0.0",
    "stylelint": "11.0.0",
    "stylelint-config-recommended-scss": "4.0.0",
    "stylelint-config-standard": "19.0.0",
    "stylelint-scss": "3.11.1"
  },
  "engines": {
    "node": ">=8"
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 21

Typescript 3.8.0 支持纯类型导入和导出。

设置 Typescript version >= 3.8.0 以解决此错误。