chenshuai2144 / openapi2typescript

一个被大范围使用的小工具
326 stars 141 forks source link

按照示例抄的生成,但是运行的时候报错:Unknown file extension ".ts" #163

Open Anarchism-Noob opened 6 months ago

Anarchism-Noob commented 6 months ago

具体报错内容如下: $ ts-node './src/core/openapi/index.ts' TypeError: Unknown file extension ".ts" for */src/core/openapi/index.ts at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:176:9) at defaultGetFormat (node:internal/modules/esm/get_format:219:36) at defaultLoad (node:internal/modules/esm/load:133:22) at async ModuleLoader.load (node:internal/modules/esm/loader:555:7) at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:436:45) at async ModuleJob._link (node:internal/modules/esm/module_job:106:19) { code: 'ERR_UNKNOWN_FILE_EXTENSION' } error: script "openapi" exited with code 1 这个问题我查了好多都没解决,问G大模型也没用

waterbird-i commented 5 months ago

我也遇到了同样的问题,使用create-vue脚手架,node 18.20.3版本。

Stephenqhd30 commented 5 months ago

ant-design-vue-starter@0.0.0 openapi ts-node openapi.config.ts

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\Stephen\Popcorn\ant-design-vue-starter\openapi.config.ts at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9) at defaultGetFormat (node:internal/modules/esm/get_format:203:36) at defaultLoad (node:internal/modules/esm/load:143:22) at async nextLoad (node:internal/modules/esm/hooks:866:22) at async nextLoad (node:internal/modules/esm/hooks:866:22) at async Hooks.load (node:internal/modules/esm/hooks:449:20) at async MessagePort.handleMessage (node:internal/modules/esm/worker:196:18) { code: 'ERR_UNKNOWN_FILE_EXTENSION' }

我也遇见了同样的问题 node -v v20.15.0 现在又解决的办法嘛

前段时间还是可以用的

rookie-luochao commented 4 months ago

我在 openapi-ts-request 解决了这个问题,这个包是基于陈帅大佬的 openapi2typescript 暴力改造的,详见感谢部分

Anarchism-Noob commented 4 months ago

我在 openapi-ts-request 解决了这个问题,这个包是基于陈帅大佬的 openapi2typescript 暴力改造的,详见感谢部分

劳烦指个路,感谢大佬

rookie-luochao commented 4 months ago

ts-node 有时候需要在tsconfig里面配置一下,使用 CosmiConfig 配置文件的方式可以应对你不会配置的情况

yiran52 commented 3 months ago

我使用 "openapi": "npx tsx ./src/utils/openapi.config.ts"解决了