简体   繁体   English

TypeScript 错误“TS2354:此语法需要导入的帮助程序,但找不到模块‘tslib’”

[英]TypeScript error "TS2354: This syntax requires an imported helper but module 'tslib' cannot be found"

I have reduced a problem with TypeScript to the following example.我已将 TypeScript 的问题简化为以下示例。 When trying to run tsc, I get the following error message but tslib should be available.尝试运行 tsc 时,我收到以下错误消息,但tslib应该可用。

https://codesandbox.io/s/quizzical-mclean-n9vvi?fontsize=14&hidenavigation=1&theme=dark 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 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 tsconfig.json

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

index.js索引.js

'use strict';

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

The issue has now been confirmed as a bug in TypeScript https://github.com/microsoft/TypeScript/issues/37991该问题现已确认为 TypeScript https://github.com/microsoft/TypeScript/issues/37991中的错误

I think you need to install "tslib" using the following command.我认为您需要使用以下命令安装“tslib”。

npm i -g tslib

I Resolve this issue by using below copy-anything npm command我通过使用下面copy-anything npm 命令解决了这个问题

npm i copy-anything

The answer to this question error TS2307: Cannot find module '@angular/core' , which is这个问题error TS2307: Cannot find module '@angular/core'的答案是

npm install --save @angular/material @angular/cdk
rm -rf node_modules
npm install

solved my issue.解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 ES2015 模块时出现“此语法需要导入的帮助程序,但找不到模块‘tslib’” - "This syntax requires an imported helper but module 'tslib' cannot be found" with ES2015 modules 如何在TypeScript 2.1.4中使TS2354错误消息静音? - How can I silence the TS2354 error message in TypeScript 2.1.4? 引用外部 typescript 文件时如何避免“找不到模块:错误:无法解析 'tslib'”-错误? - How to avoid “Module not found: Error: Can't resolve 'tslib'”-error when referencing an external typescript file? 导入模块时无法找到ts文件中的功能 - Function in ts file cannot be found when module is imported 该语法需要一个名为 __spreadArrays 的导入助手 - the syntax requires an imported helper named __spreadArrays 打字稿、index.d.ts 和 webpack:找不到模块错误 - Typescript, index.d.ts and webpack: Module not found error Typescript index.ts 激活时出现错误“未找到模块” - ERROR "MODULE NOT FOUND" on Typescript index.ts activation Visual Studio Code:Angular 项目中的“找不到‘tslib’”错误 - Visual Studio Code: "'tslib' cannot be found" error in Angular project 打字稿编译器错误 TS2307:找不到模块“jquery” - Typescript Compiler error TS2307: Cannot find module 'jquery' 找不到导入的模块TypeScript - Cannot find imported Module TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM