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

2023-12-20 06:31:59

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
  }
}

文章来源:https://blog.csdn.net/baidu_41601048/article/details/135033830
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。