【问题标题】:TypeScript error "TS2354: This syntax requires an imported helper but module 'tslib' cannot be found"TypeScript 错误“TS2354:此语法需要导入的帮助程序,但找不到模块 'tslib'”
【发布时间】:2020-04-14 11:17:25
【问题描述】:

我已将 TypeScript 的问题简化为以下示例。尝试运行 tsc 时,我收到以下错误消息,但 tslib 应该可用。

https://codesandbox.io/s/quizzical-mclean-n9vvi?fontsize=14&hidenavigation=1&theme=dark

$ tsc --noEmit --project ./tsconfig.json

index.js:3:8 - error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

3 const {ArgumentParser} = require('argparse');
         ~~~~~~~~~~~~~~
Found 1 error.

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "test": "tsc --noEmit --project ./tsconfig.json"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/argparse": "1.0.38",
    "argparse": "1.0.10",
    "tslib": "1.11.1",
    "typescript": "3.8.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "checkJs": true,
    "allowJs": true,
    "moduleResolution": "node",
    "target": "es2018",
    "module": "commonjs",
    "importHelpers": true,
    "lib": [
      "es2018"
    ]
  },
  "include": [
    "*.js"
  ],
  "exclude": [
    "node_modules"
  ]
}

index.js

'use strict';

const {ArgumentParser} = require('argparse');

【问题讨论】:

    标签: typescript


    【解决方案1】:

    该问题现已确认为 TypeScript https://github.com/microsoft/TypeScript/issues/37991 中的错误

    【讨论】:

      【解决方案2】:

      我认为您需要使用以下命令安装“tslib”。

      npm i -g tslib
      

      【讨论】:

        猜你喜欢
        • 2019-03-19
        • 2012-06-01
        • 2018-09-05
        • 2017-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多