【问题标题】:gulp serve shows [tsc] typescript version: 3.3.4000 while package.json has "typescript": "^4.0.3"gulp serve 显示 [tsc] typescript version: 3.3.4000 而 package.json 有 "typescript": "^4.0.3"
【发布时间】:2020-10-09 12:27:32
【问题描述】:

我在我的 react 应用中安装了 jest 和 testing-creat-library,但是当我进行 gulp 构建时,我收到以下错误:

[14:11:27] Error - [tsc] node_modules/@testing-library/dom/node_modules/pretty-format/build/index.d.ts(7,13): error TS1005: '=' expected.
[14:11:27] Error - [tsc] node_modules/@testing-library/dom/node_modules/pretty-format/build/index.d.ts(7,18): error TS1005: ';' expected.
[14:11:27] Error - [tsc] node_modules/@testing-library/dom/node_modules/pretty-format/build/index.d.ts(7,31): error TS1005: ';' expected.
[14:11:27] Error - [tsc] node_modules/@testing-library/dom/node_modules/pretty-format/build/index.d.ts(7,36): error TS1005: ';' expected.
[14:11:27] Error - 'tsc' sub task errored after 3.57 s

在github issue page 之后,我将我的打字稿从 3.8.3 升级到了 4.0.3。它仍然没有解决我的问题。

但是当我运行 gulp build 时,我看到以下内容:[tsc] typescript version: 3.3.4000 为什么它仍然引用旧版本,而在 package.json 中我指定了更高版本?

我该如何解决上面的错误?


package.json

 "dependencies": {
    "@microsoft/sp-core-library": "1.11.0",
    "@microsoft/sp-lodash-subset": "1.11.0",
    "@microsoft/sp-office-ui-fabric-core": "1.11.0",
    "@microsoft/sp-property-pane": "1.11.0",
    "@microsoft/sp-webpart-base": "1.11.0",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.0.4",
    "@types/jest": "^26.0.14",
    "@types/node": "^14.11.8",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^26.5.2",
    "jest-junit": "^12.0.0",
    "office-ui-fabric-react": "6.214.0",
    "react": "16.8.5",
    "react-dom": "16.8.5",
    "react-test-renderer": "^16.13.1",
    "ts-jest": "^26.4.1",
    "typescript": "^4.0.3"
  },
  "devDependencies": {
    "@microsoft/rush-stack-compiler-3.3": "0.3.5",
    "@microsoft/sp-build-web": "1.11.0",
    "@microsoft/sp-module-interfaces": "1.11.0",
    "@microsoft/sp-tslint-rules": "1.11.0",
    "@microsoft/sp-webpart-workbench": "1.11.0",
    "@types/chai": "3.4.34",
    "@types/es6-promise": "0.0.33",
    "@types/mocha": "2.2.38",
    "@types/react": "^16.8.8",
    "@types/react-dom": "^16.8.3",
    "@types/webpack-env": "1.13.1",
    "ajv": "^5.2.2",
    "gulp": "^3.9.1"
  }

【问题讨论】:

  • 这取决于您未显示的设置。显然,您的部门中有 3.3。
  • 不知道如何提升它。
  • 不知道TS在Gulp任务中是如何使用的,所以不知道使用的是哪个副本以及如何更新。

标签: typescript jestjs gulp testng spfx


【解决方案1】:

如果您希望 SPFx 使用不同版本的 TypeScript,您需要更改您的 @microsoft/rush-stack-compiler-3.3 依赖项。 你可以选择你想要的 TypeScript 版本here。

安装新的@microsoft/rusk-stack-compiler 后,您必须在tsconfig.json 的顶部进行更改。

【讨论】:

    猜你喜欢
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 2020-03-05
    • 1970-01-01
    • 2012-10-05
    • 2017-03-23
    相关资源
    最近更新 更多