diff --git a/public/mdImages/Pasted image 20250226143746.png b/public/mdImages/IMG-3F25D1B9A693916B658415B17B64FDF4.png similarity index 100% rename from public/mdImages/Pasted image 20250226143746.png rename to public/mdImages/IMG-3F25D1B9A693916B658415B17B64FDF4.png diff --git a/public/mdImages/Pasted image 20250226143342.png b/public/mdImages/IMG-54444FCBA889BF74A543004B4163532D.png similarity index 100% rename from public/mdImages/Pasted image 20250226143342.png rename to public/mdImages/IMG-54444FCBA889BF74A543004B4163532D.png diff --git a/public/mdImages/IMG-59000B6CA38DF6FF4AB23AAA2920FF6F.png b/public/mdImages/IMG-59000B6CA38DF6FF4AB23AAA2920FF6F.png new file mode 100644 index 0000000..7ae214c Binary files /dev/null and b/public/mdImages/IMG-59000B6CA38DF6FF4AB23AAA2920FF6F.png differ diff --git a/public/mdImages/Pasted image 20250226143542.png b/public/mdImages/IMG-647D50202A16E26E1BE25AE4FC4E5DA1.png similarity index 100% rename from public/mdImages/Pasted image 20250226143542.png rename to public/mdImages/IMG-647D50202A16E26E1BE25AE4FC4E5DA1.png diff --git a/public/mdImages/IMG-pip运行的时候如何设置环境变量-CDC2BAD93093406D70B0F9A6F01B86BF.png b/public/mdImages/IMG-CDC2BAD93093406D70B0F9A6F01B86BF.png similarity index 100% rename from public/mdImages/IMG-pip运行的时候如何设置环境变量-CDC2BAD93093406D70B0F9A6F01B86BF.png rename to public/mdImages/IMG-CDC2BAD93093406D70B0F9A6F01B86BF.png diff --git a/public/mdImages/Pasted image 20250226143633.png b/public/mdImages/IMG-D9D3E5481059773AA8CCB5718E5EFB06.png similarity index 100% rename from public/mdImages/Pasted image 20250226143633.png rename to public/mdImages/IMG-D9D3E5481059773AA8CCB5718E5EFB06.png diff --git a/src/content/note/2023-09-12.md b/src/content/note/2023-09-12.md index ba6bce1..8a81e7a 100644 --- a/src/content/note/2023-09-12.md +++ b/src/content/note/2023-09-12.md @@ -27,9 +27,9 @@ date_modified: 20250304 ## 今天要做的事情 - [ ] 刷题回顾 - - [x] [86.分隔链表](https://notes.kazoottt.top/03-领域/编程/算法/记录/86.分隔链表) - - [x] [141.环形链表](https://notes.kazoottt.top/03-领域/编程/算法/记录/141.环形链表) - - [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/编程/算法/记录/142.环形链表-ii) + - [x] [86.分隔链表](https://notes.kazoottt.top/03-领域/算法/记录/86.分隔链表) + - [x] [141.环形链表](https://notes.kazoottt.top/03-领域/算法/记录/141.环形链表) + - [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/算法/记录/142.环形链表-ii) - [ ] [[160.相交链表]] - [x] [[obsidian链接外部代码文件]] diff --git a/src/content/note/2023-09-13.md b/src/content/note/2023-09-13.md index ce00ab2..be51fb3 100644 --- a/src/content/note/2023-09-13.md +++ b/src/content/note/2023-09-13.md @@ -39,8 +39,8 @@ date_modified: 20250304 ## 今天要做的事情 - [ ] 刷题回顾 - - [x] [141.环形链表](https://notes.kazoottt.top/03-领域/编程/算法/记录/141.环形链表) - - [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/编程/算法/记录/142.环形链表-ii) + - [x] [141.环形链表](https://notes.kazoottt.top/03-领域/算法/记录/141.环形链表) + - [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/算法/记录/142.环形链表-ii) - [ ] [[160.相交链表]] ## 打卡 diff --git a/src/content/note/2023-11-16.md b/src/content/note/2023-11-16.md index 722c096..ac8cdcd 100644 --- a/src/content/note/2023-11-16.md +++ b/src/content/note/2023-11-16.md @@ -27,7 +27,7 @@ date_modified: 20250304 开始学习 web3,上周报名的 open build 的 solidity_bootcamp 开营了。 -[solidity_bootcamp学习笔记](https://notes.kazoottt.top/03-领域/编程/web3/solidity_bootcamp学习笔记) +[solidity_bootcamp学习笔记](https://notes.kazoottt.top/03-领域/web3/solidity_bootcamp学习笔记) ## Inbox diff --git a/src/content/note/2024-03-05.md b/src/content/note/2024-03-05.md index 7935893..7e2f58a 100644 --- a/src/content/note/2024-03-05.md +++ b/src/content/note/2024-03-05.md @@ -21,13 +21,13 @@ date_modified: 20250304 # 今天要做的事情 -- [x] python 看到 day15 [python100 1-15](https://notes.kazoottt.top/03-领域/编程/后端/python/python100 1-15) +- [x] python 看到 day15 [python100 1-15](https://notes.kazoottt.top/03-领域/后端/python/python100 1-15) - [x] 刷题 - [ ] 整理周一和周二的资讯 - [ ] 多线程批量跑测试 - [ ] [[AttributeError module 'select' has no attribute 'epoll']] - [ ] [[jerbrains的ide打不开terminal]] -- [ ] [2024-03-05 刷题](https://notes.kazoottt.top/03-领域/编程/算法/记录/2024-03-05 刷题) +- [ ] [2024-03-05 刷题](https://notes.kazoottt.top/03-领域/算法/记录/2024-03-05 刷题) # 打卡 diff --git a/src/content/note/pip安装和运行openwebui.md b/src/content/note/pip安装和运行openwebui.md index 8e1efc1..929d514 100644 --- a/src/content/note/pip安装和运行openwebui.md +++ b/src/content/note/pip安装和运行openwebui.md @@ -27,7 +27,7 @@ finished: true [GitHub - open-webui/open-webui: User-friendly AI Interface (Supports Ollama, OpenAI API, ...)]() -![IMG-pip运行的时候如何设置环境变量-CDC2BAD93093406D70B0F9A6F01B86BF]() +![IMG-CDC2BAD93093406D70B0F9A6F01B86BF]() @@ -56,7 +56,7 @@ open-webui : 无法将“open-webui”项识别为 cmdlet、函数、脚本文 pip show requests ``` -![Pasted image 20250226143342]() +![IMG-54444FCBA889BF74A543004B4163532D]() 能够看到这里面的 location, 所以实际的 script 的路径就是这个(site-packges 替换为 Scripts) @@ -68,15 +68,15 @@ C:\Users\turbo\AppData\Roaming\Python\Python312\Scripts ### 如何编辑环境变量 -![Pasted image 20250226143542]() +![IMG-647D50202A16E26E1BE25AE4FC4E5DA1]() 搜索环境变量,进入编辑窗口 -![Pasted image 20250226143633]() +![IMG-D9D3E5481059773AA8CCB5718E5EFB06]() 然后编辑系统变量把刚刚的那段路径添加到里面就可以了 -![Pasted image 20250226143746]() +![IMG-3F25D1B9A693916B658415B17B64FDF4]() 然后再打开一个命令行运行 diff --git a/src/content/post/2023-W46.md b/src/content/post/2023-W46.md index 661aa71..00422d3 100644 --- a/src/content/post/2023-W46.md +++ b/src/content/post/2023-W46.md @@ -39,7 +39,7 @@ date_modified: 20250304 然后这周也是我**开始认真学习理财知识**的一周,也办了港澳通行证,打算找个时间去香港开户。 -与此同时 [solidity_bootcamp学习笔记](https://notes.kazoottt.top/03-领域/编程/web3/solidity_bootcamp学习笔记) 也开课了,这周学习了区块链的基本概念以及 solidity 语法(虽然这节课我睡过了头) +与此同时 [solidity_bootcamp学习笔记](https://notes.kazoottt.top/03-领域/web3/solidity_bootcamp学习笔记) 也开课了,这周学习了区块链的基本概念以及 solidity 语法(虽然这节课我睡过了头) 周末的时候,用 tailwindcss 手搓了两个投稿的封面,以后也用这种方式来练习吧。 @@ -59,7 +59,7 @@ date_modified: 20250304 ### Web3 相关 -[solidity_bootcamp学习笔记](https://notes.kazoottt.top/03-领域/编程/web3/solidity_bootcamp学习笔记) +[solidity_bootcamp学习笔记](https://notes.kazoottt.top/03-领域/web3/solidity_bootcamp学习笔记) ### 10 Best Websites to Help You Practice JavaScript diff --git a/src/content/post/如何运行 ts 文件.md b/src/content/post/如何运行 ts 文件.md new file mode 100644 index 0000000..8210ecb --- /dev/null +++ b/src/content/post/如何运行 ts 文件.md @@ -0,0 +1,161 @@ +--- +toAstro: true +astroType: post +published: true +toWexin: true +toJuejin: null +toZhihu: true +description: >- + 本文针对在 VSCode 中运行 TypeScript 文件时遇到的问题,提供了多种解决方案。比较了不同方式的优缺点,特别强调了 bun + 在速度和易用性方面的优势,以及 ts-node 配置的复杂性。同时,文章还指导用户如何配置 Code Runner 扩展,以便更方便地运行 + TypeScript 代码。 +date: 20250225 +tags: + - bun + - code + - runner + - ts-node + - typescript + - vscode +category: 前端 +slug: how-to-run-ts-files +date_created: 20250225 +date_modified: 20250306 +title: 如何运行 ts 文件 +--- + +![cover]() + +在 VSCode 中安装扩展 Code Runner,我创建了一个 .ts 文件,点击运行按钮,但提示 + +> 'ts-node' 不是内部或外部命令 +> 'ts-node' is not recognized as an internal or external command + +解决方法是全局安装 ts-node,例如: + +``` shell +pnpm i -g ts-node +``` + +但在我安装之后,错误确实消失了,却又提示另一个错误 + +``` log +TypeError: Unknown file extension ".ts" for /xxx/xxx/test.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:554:7) + at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:435:45) + at async ModuleJob._link (node:internal/modules/esm/module_job:106:19) { + code: 'ERR_UNKNOWN_FILE_EXTENSION' +} +``` + +所以我认为或许不止我一个人对于如何运行 ts 文件有疑问,所以本篇文章就来介绍一下如何在 VSCode 中运行 ts 文件,以及回到最初的问题,如何在 code runner 中运行 ts 文件。 + +## 如何运行 ts 文件 + +我们准备一个简单的的 ts 文件,命名为 index.ts,来作为测试的文件。 + +``` typescript +const a: number = 1; +const b: number = 2; +const c: number = a + b; +console.log(c); +``` + +### bun 运行 ts 文件(目前最推荐) + +``` shell +bun index.ts +``` + +![alt text]() + +### 使用 tsc 将 ts 编译为 js,然后 node 运行 + +TypeScript Compiler (tsc) 是 TypeScript 的编译器,它可以将 TypeScript 代码编译为 JavaScript 代码。我们可以使用 tsc 命令来编译 TypeScript 文件。 + +``` shell +tsc index.ts +node index.js +``` + +![alt text]() + +### tsx (TypeScript Executer) 运行 ts 文件 + +``` shell +npx tsx index.ts +``` + +![alt text]() + +### Node.js V22.7.0 直接运行文件 + +``` shell +node --experimental-strip-types index.ts +``` + +![alt text]() + +### ts-node 运行 ts 文件(不推荐) + +``` shell +ts-node index.ts +``` + +![alt text]() + +这个问题频繁出现于 ts-node 的 issues 中,有一个讨论甚至到了 70+ 也没有关闭 + +![alt text]() + +要解决这里的报错,需要做几件事情: + +1. 必须要有 package.json 并且 "type": "module" + 1. 如果没有 package.json, 运行 `npm init -y` 生成 package.json +2. tsconfig.json 中 "module" 不能是 "commonjs" ,必须要有 'module': 'ESNext' 或者 'module': 'ES6'。 + 1. 如果没有 tsconfig.json, 运行 `npx tsc --init` 生成 tsconfig.json +3. 运行的时候必须要有 --loader ts-node/esm + +``` shell +node --loader ts-node/esm index.ts +``` + +![alt text]() + +## 如何在 coder runner 中运行 ts 文件 + +最简单的方法:在 code-runner.executorMap 中修改 typescript 的配置: + +``` json +{ + "typescript": "bun $fullFileName" +} +``` + +也可以这样写,然后会生成一个 js 文件,然后运行 js 文件: + +``` json +{ + "typescript": "tsc $fullFileName && node $fileNameWithoutExt.js" +} +``` + +不过这样的速度是比较慢的 + +![alt text]() + +- 使用 `bun $fullFileName`: + 耗时:0.295 秒 + +- 使用 tsc `tsc $fullFileName && node $fileNameWithoutExt.js`: + + 耗时:2.523 秒 + +## 总结 + +无论是运行 ts 文件还是在 code runner 中运行 ts 文件,最推荐的方式是使用 bun 来运行 ts 文件。它的速度和开箱即用的特性都非常好。 + +最不推荐的是 ts-node,需要有很严格的配置,且官方没有提供明确的文档来说明如何配置,更多的是靠开源社区的讨论来解决问题。 diff --git a/src/content/post/封面生成器推荐.md b/src/content/post/封面生成器推荐.md index da94a3d..2b9b401 100644 --- a/src/content/post/封面生成器推荐.md +++ b/src/content/post/封面生成器推荐.md @@ -16,7 +16,7 @@ slug: cover-generator description: >- 本收集涵盖了多个封面生成工具和资源,旨在帮助用户快速创建美观且专业的封面设计。这些工具包括在线封面生成器、设计模板库以及自定义封面设计的技巧和指南。无论是用于书籍、报告、社交媒体还是其他用途,这些资源都能满足不同用户的需求,提升视觉呈现效果。 date_created: 20250206 -date_modified: 20250302 +date_modified: 20250306 finished: true category: 软件 banner: >- @@ -100,3 +100,15 @@ banner: >- [GitHub 仓库]() ![IMG-AEE6D7C35A6347C5F792B7FCC509C795]() + +## Imaker + +20250305 更新 Imaker + +[GitHub - slince-zero/IMaker: Create striking covers effortlessly with our easy-to-use IMaker.]() + +[IMaker]() + +![IMG-59000B6CA38DF6FF4AB23AAA2920FF6F]() + +字体大小不能调大很大