二、TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" 解决办法 {"compilerOptions":{"module":"ESNext"// or ES2015, ES2020},"ts-node":{"esm":true}}
at MessagePort.handleMessage (node:internal/modules/esm/worker:168:24) at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20) { code: 'ERR_UNKNOWN_FILE_EXTENSION' } tsconfig: "compilerOptions": {"target":"es2016","module":"esnext","esModuleInterop":true, } Nov 22, ...
//tsconfig.json{"compilerOptions": {"target":"ESNext","module":"NodeNext","moduleResolution":"NodeNext","outDir":"dist","esModuleInterop":true,"strict":true,"skipLibCheck":true},"ts-node": {"esm":true},"exclude": ["node_modules","./*.ts","__test__"] }//package.json{ ....
I made a tiny project trying to isolate the issue as much as possible package.json {"type":"module"} tsconfig.json {"compilerOptions":{"module":"es2020","baseUrl":"./","paths":{"$lib/*":["src/lib/*"]},},"ts-node":{"esm":true}} test.ts import{ testFn }from"$lib/module...
"ts-node": { "files": true, "esm": true, }, And even using the FASTIFY_AUTOLOAD_TYPESCRIPT=1 flag like so: FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --no-warnings=ExperimentalWarning --loader ts-node/esm src/index.ts npm start which will use tsc will work fine! However running the command...
我又看了一圈官方文档,说是让用node --loader ts-node/esm来执行 image-20210814152034219 于是,我就换了这个命令,结果又换了新错误。 image-20210814152131588 (node:65419) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time ...
NODE_OPTIONS="--loader ts-node/esm" This tells any node processes which receive this environment variable to installts-node's hooks before executing other code. If you are invoking node directly, you can avoid the environment variable and pass those flags to node. ...
我使用的配置与您的配置相同,但仅在我降级到ts-node@9时有效,然后我在我的.mocharc.json中尝试了...
另外ts-node启用的功能是将现代 esm 语法转换为 CommonJS 语法。这意味着在使用时 ts-node,您可以在代码中通 import 而不是 require 使用 node 模块。 package.json 中新增脚本: {"scripts":{"dev":"ts-node src/index.ts"}} 使用tsc-node-dev可以监听文件的变化,当文件内容变化后重新编译并运行。
{ "compilerOptions": { "esModuleInterop": true, } } 然后您可以使用配置启动服务器 ts-node。 安装: npm install -g ts-node 跑: ts-node-esm my_server.ts 原文由 vadimk7 发布,翻译遵循 CC BY-SA 4.0 许可协议 有用 回复 社区维基1 发布于 2022-10-11 采用 node --loader ts-node...