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

1 node_modules/@types/express/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.

解决办法:

 "compilerOptions": {
    
    "esModuleInterop":true
  }

2  TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

"scripts": {
    "dev": "vite",
    "service":"nodemon service.ts",
}

这里通过nodemon运行service.ts报错。

解决办法:去掉pack.json中的type:module

{
  "name": "tsv3",
  "private": true,
 // "type": "module",  //去掉
  "scripts": {
    "dev": "vite",
    "service":"nodemon service.ts",
   
  }

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

解决办法:(注意:"ts-node"选项和complierOptions同级)

{
  "compilerOptions": {
    "module": "ESNext" // or ES2015, ES2020
  },
  "ts-node": {
    // Tell ts-node CLI to install the --loader automatically, explained below
    "esm": true
  }
}

最近更新

  1. TCP协议是安全的吗?

    2023-12-22 06:50:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-22 06:50:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-22 06:50:03       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-22 06:50:03       20 阅读

热门阅读

  1. Go使用websocket

    2023-12-22 06:50:03       38 阅读
  2. 基于Spring Boot的支教志愿者招聘网站

    2023-12-22 06:50:03       47 阅读
  3. Ubuntu22.04安装python2

    2023-12-22 06:50:03       51 阅读
  4. SpringBoot数据校验

    2023-12-22 06:50:03       42 阅读
  5. 使用GBASE南大通用负载均衡连接池

    2023-12-22 06:50:03       32 阅读
  6. FFmpeg实现rtp推流

    2023-12-22 06:50:03       33 阅读
  7. VTK数据结构

    2023-12-22 06:50:03       42 阅读
  8. Qt使用ffmpeg获取视频文件封面图

    2023-12-22 06:50:03       30 阅读
  9. 【WebRTC---源码篇】(二十五)音视频同步

    2023-12-22 06:50:03       47 阅读