基于ts的node项目引入报错归纳

一、导入类型定义文件错误

node_modules/@types/leaflet/index.d.ts:128:1
    128 export = e;
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

这个错误表明使用 export = 语法,但 TypeScript 配置中没有启用 esModuleInterop 标志。
这个错误通常出现在导入类型定义文件时,特别是在使用 CommonJS 的情况下。
解决办法

 "compilerOptions": {
    "esModuleInterop":true
  }

二、TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

解决办法

{
  "compilerOptions": {
    "module": "ESNext" // or ES2015, ES2020
  },
  "ts-node": {
    "esm": true
  }
}
posted @ 2024-03-13 23:33  槑孒  阅读(171)  评论(0编辑  收藏  举报