【问题标题】:Suppress an ERRNO 2 error in typescript compilation抑制打字稿编译中的 ERRNO 2 错误
【发布时间】:2019-08-28 19:30:21
【问题描述】:

我的编译中有以下错误:

node_modules/@types/jest/index.d.ts(256,23): error TS1144: '{' or ';' expected.
node_modules/@types/jest/index.d.ts(258,9): error TS1005: '(' expected.
node_modules/@types/jest/index.d.ts(258,16): error TS1005: ')' expected.
node_modules/@types/jest/index.d.ts(278,26): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(278,50): error TS1005: ',' expected.
node_modules/@types/jest/index.d.ts(279,31): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(279,56): error TS1005: '(' expected.
node_modules/@types/jest/index.d.ts(279,62): error TS1005: ',' expected.
node_modules/@types/jest/index.d.ts(279,69): error TS1005: ')' expected.
node_modules/@types/jest/index.d.ts(280,31): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(280,57): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(280,60): error TS1109: Expression expected.
node_modules/@types/jest/index.d.ts(282,63): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(282,115): error TS1005: ',' expected.
node_modules/@types/jest/index.d.ts(284,60): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(284,104): error TS1128: Declaration or statement expected.
node_modules/@types/jest/index.d.ts(284,112): error TS1005: ',' expected.
node_modules/@types/jest/index.d.ts(404,32): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(404,33): error TS1003: Identifier expected.
node_modules/@types/jest/index.d.ts(912,11): error TS1005: '>' expected.
node_modules/@types/jest/index.d.ts(912,24): error TS1109: Expression expected.
node_modules/@types/jest/index.d.ts(912,39): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(912,40): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(912,42): error TS1128: Declaration or statement expected.
node_modules/@types/jest/index.d.ts(913,7): error TS1109: Expression expected.
node_modules/@types/jest/index.d.ts(914,22): error TS1005: ',' expected.
node_modules/@types/jest/index.d.ts(914,30): error TS1005: ':' expected.
node_modules/@types/jest/index.d.ts(914,74): error TS1005: '(' expected.
node_modules/@types/jest/index.d.ts(914,81): error TS1005: ')' expected.
node_modules/@types/jest/index.d.ts(929,30): error TS1005: ';' expected.
node_modules/@types/jest/index.d.ts(931,13): error TS1005: '(' expected.
node_modules/@types/jest/index.d.ts(931,20): error TS1005: ',' expected.
node_modules/@types/jest/index.d.ts(933,13): error TS1005: '(' expected.
node_modules/@types/jest/index.d.ts(934,5): error TS1005: ',' expected.
node_modules/@types/jest/index.d.ts(934,7): error TS1109: Expression expected.
node_modules/@types/jest/index.d.ts(935,10): error TS1005: ')' expected.
node_modules/@types/jest/index.d.ts(1128,1): error TS1128: Declaration or statement expected.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! SocleTechniqueClient@0.0.0 tsc-compile-client: `node ./node_modules/typescript/bin/tsc -p projects/framework/tsconfig.client.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the SocleTechniqueClient@0.0.0 tsc-compile-client script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我希望我的编译在没有此错误的情况下运行,但是我无法修复该错误,因为它是由于我的 typescript 版本 (2.7.1) 和输入文件的 jest 语法不兼容。

因此,我希望完全消除错误。一些研究引导我使用 --silent 选项,它实际上抑制了 npm ERR! errno 2 但我仍然得到 jest 输入的所有语法错误行。

这个post 建议在tsconfig 文件中添加一个"skipLibCheck": true,但它对我不起作用。

我正在寻找一种方法来抑制这些消息。

顺便说一句: 我的tsconfig 看起来像这样:

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    "moduleResolution": "classic",
    "sourceMap": true,
    "inlineSources": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "target": "es5",
    "outDir": "../../build/",
    "outFile": "../../build/framework-client.js",
    "typeRoots": [
      "node_modules/@types",
      "../../node_modules/typescript/lib/lib.d.ts"
    ],
    "types": ["jest"]
  },
  "files": [...]
}

【问题讨论】:

    标签: typescript jestjs


    【解决方案1】:

    只需排除您的 node_modules 文件夹。更新你的 tsconfig 文件到

    {
      "compileOnSave": false,
      "compilerOptions": {
        "allowJs": true,
        "moduleResolution": "classic",
        "sourceMap": true,
        "inlineSources": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "skipLibCheck": true,
        "target": "es5",
        "outDir": "../../build/",
        "outFile": "../../build/framework-client.js",
        "typeRoots": [
          "node_modules/@types",
          "../../node_modules/typescript/lib/lib.d.ts"
        ],
        "types": ["jest"]
      },
      "files": [...]
      "exclude": [
        "node_modules"
      ]
    }
    

    【讨论】:

    • 嗨,实际上这会让我遇到其他错误error TS2304: Cannot find name 'fail'.expectit 等)。因此,虽然我想避免开玩笑打字的编译错误,但我想编译包含这些关键字的文件!
    • 也许一个更精确的问题是如何在旧版本的打字稿(2.7.1 和更早版本)的编译中处理测试类型?
    猜你喜欢
    • 1970-01-01
    • 2018-02-12
    • 2017-06-26
    • 2016-09-09
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    相关资源
    最近更新 更多