Update docs and sort content

This commit is contained in:
github-actions[bot]
2025-03-06 07:11:30 +00:00
parent 8e7273da0c
commit a9879a68b1
14 changed files with 189 additions and 16 deletions

View File

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 112 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 KiB

View File

Before

Width:  |  Height:  |  Size: 359 KiB

After

Width:  |  Height:  |  Size: 359 KiB

View File

Before

Width:  |  Height:  |  Size: 159 KiB

After

Width:  |  Height:  |  Size: 159 KiB

View File

@ -27,9 +27,9 @@ date_modified: 20250304
## 今天要做的事情 ## 今天要做的事情
- [ ] 刷题回顾 - [ ] 刷题回顾
- [x] [86.分隔链表](https://notes.kazoottt.top/03-领域/编程/算法/记录/86.分隔链表) - [x] [86.分隔链表](https://notes.kazoottt.top/03-领域/算法/记录/86.分隔链表)
- [x] [141.环形链表](https://notes.kazoottt.top/03-领域/编程/算法/记录/141.环形链表) - [x] [141.环形链表](https://notes.kazoottt.top/03-领域/算法/记录/141.环形链表)
- [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/编程/算法/记录/142.环形链表-ii) - [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/算法/记录/142.环形链表-ii)
- [ ] [[160.相交链表]] - [ ] [[160.相交链表]]
- [x] [[obsidian链接外部代码文件]] - [x] [[obsidian链接外部代码文件]]

View File

@ -39,8 +39,8 @@ date_modified: 20250304
## 今天要做的事情 ## 今天要做的事情
- [ ] 刷题回顾 - [ ] 刷题回顾
- [x] [141.环形链表](https://notes.kazoottt.top/03-领域/编程/算法/记录/141.环形链表) - [x] [141.环形链表](https://notes.kazoottt.top/03-领域/算法/记录/141.环形链表)
- [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/编程/算法/记录/142.环形链表-ii) - [ ] [142.环形链表-ii](https://notes.kazoottt.top/03-领域/算法/记录/142.环形链表-ii)
- [ ] [[160.相交链表]] - [ ] [[160.相交链表]]
## 打卡 ## 打卡

View File

@ -27,7 +27,7 @@ date_modified: 20250304
开始学习 web3上周报名的 open build 的 solidity_bootcamp 开营了。 开始学习 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 ## Inbox

View File

@ -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] 刷题 - [x] 刷题
- [ ] 整理周一和周二的资讯 - [ ] 整理周一和周二的资讯
- [ ] 多线程批量跑测试 - [ ] 多线程批量跑测试
- [ ] [[AttributeError module 'select' has no attribute 'epoll']] - [ ] [[AttributeError module 'select' has no attribute 'epoll']]
- [ ] [[jerbrains的ide打不开terminal]] - [ ] [[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 刷题)
# 打卡 # 打卡

View File

@ -27,7 +27,7 @@ finished: true
[GitHub - open-webui/open-webui: User-friendly AI Interface (Supports Ollama, OpenAI API, ...)](<https://github.com/open-webui/open-webui?tab=readme-ov-file#installation-via-python-pip->) [GitHub - open-webui/open-webui: User-friendly AI Interface (Supports Ollama, OpenAI API, ...)](<https://github.com/open-webui/open-webui?tab=readme-ov-file#installation-via-python-pip->)
![IMG-pip运行的时候如何设置环境变量-CDC2BAD93093406D70B0F9A6F01B86BF](</mdImages/IMG-pip运行的时候如何设置环境变量-CDC2BAD93093406D70B0F9A6F01B86BF.png>) ![IMG-CDC2BAD93093406D70B0F9A6F01B86BF](</mdImages/IMG-CDC2BAD93093406D70B0F9A6F01B86BF.png>)
<!--section: 1.1--> <!--section: 1.1-->
@ -56,7 +56,7 @@ open-webui : 无法将“open-webui”项识别为 cmdlet、函数、脚本文
pip show requests pip show requests
``` ```
![Pasted image 20250226143342](</mdImages/Pasted image 20250226143342.png>) ![IMG-54444FCBA889BF74A543004B4163532D](</mdImages/IMG-54444FCBA889BF74A543004B4163532D.png>)
能够看到这里面的 location, 所以实际的 script 的路径就是这个site-packges 替换为 Scripts) 能够看到这里面的 location, 所以实际的 script 的路径就是这个site-packges 替换为 Scripts)
@ -68,15 +68,15 @@ C:\Users\turbo\AppData\Roaming\Python\Python312\Scripts
### 如何编辑环境变量 ### 如何编辑环境变量
![Pasted image 20250226143542](</mdImages/Pasted image 20250226143542.png>) ![IMG-647D50202A16E26E1BE25AE4FC4E5DA1](</mdImages/IMG-647D50202A16E26E1BE25AE4FC4E5DA1.png>)
搜索环境变量,进入编辑窗口 搜索环境变量,进入编辑窗口
![Pasted image 20250226143633](</mdImages/Pasted image 20250226143633.png>) ![IMG-D9D3E5481059773AA8CCB5718E5EFB06](</mdImages/IMG-D9D3E5481059773AA8CCB5718E5EFB06.png>)
然后编辑系统变量把刚刚的那段路径添加到里面就可以了 然后编辑系统变量把刚刚的那段路径添加到里面就可以了
![Pasted image 20250226143746](</mdImages/Pasted image 20250226143746.png>) ![IMG-3F25D1B9A693916B658415B17B64FDF4](</mdImages/IMG-3F25D1B9A693916B658415B17B64FDF4.png>)
然后再打开一个命令行运行 然后再打开一个命令行运行

View File

@ -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 手搓了两个投稿的封面,以后也用这种方式来练习吧。 周末的时候,用 tailwindcss 手搓了两个投稿的封面,以后也用这种方式来练习吧。
@ -59,7 +59,7 @@ date_modified: 20250304
### Web3 相关 ### 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 ### 10 Best Websites to Help You Practice JavaScript

View File

@ -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](<https://s2.loli.net/2025/03/06/kfu6KdC2m1HoLM9.png>)
在 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](<https://s2.loli.net/2025/03/06/FOLdGi1ST9Wo4wA.png>)
### 使用 tsc 将 ts 编译为 js然后 node 运行
TypeScript Compiler (tsc) 是 TypeScript 的编译器,它可以将 TypeScript 代码编译为 JavaScript 代码。我们可以使用 tsc 命令来编译 TypeScript 文件。
``` shell
tsc index.ts
node index.js
```
![alt text](<https://s2.loli.net/2025/03/06/eCA2hNItTwjxrG9.png>)
### tsx (TypeScript Executer) 运行 ts 文件
``` shell
npx tsx index.ts
```
![alt text](<https://s2.loli.net/2025/03/06/POMlTqEnaJkbDr8.png>)
### Node.js V22.7.0 直接运行文件
``` shell
node --experimental-strip-types index.ts
```
![alt text](<https://s2.loli.net/2025/03/06/imBgjLsvEVblytO.png>)
### ts-node 运行 ts 文件(不推荐)
``` shell
ts-node index.ts
```
![alt text](<https://s2.loli.net/2025/03/06/Qm5Rn6jVTSMUGrX.png>)
这个问题频繁出现于 ts-node 的 issues 中,有一个讨论甚至到了 70+ 也没有关闭
![alt text](<https://s2.loli.net/2025/03/06/F9Bx6AgVjbD5GLl.png>)
要解决这里的报错,需要做几件事情:
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](<https://s2.loli.net/2025/03/06/N5IO21BzCTxktA7.png>)
## 如何在 coder runner 中运行 ts 文件
最简单的方法:在 code-runner.executorMap 中修改 typescript 的配置:
``` json
{
"typescript": "bun $fullFileName"
}
```
也可以这样写,然后会生成一个 js 文件,然后运行 js 文件:
``` json
{
"typescript": "tsc $fullFileName && node $fileNameWithoutExt.js"
}
```
不过这样的速度是比较慢的
![alt text](<https://s2.loli.net/2025/03/06/59HrEdRhp24iWKw.png>)
- 使用 `bun $fullFileName`
耗时0.295 秒
- 使用 tsc `tsc $fullFileName && node $fileNameWithoutExt.js`
耗时2.523 秒
## 总结
无论是运行 ts 文件还是在 code runner 中运行 ts 文件,最推荐的方式是使用 bun 来运行 ts 文件。它的速度和开箱即用的特性都非常好。
最不推荐的是 ts-node需要有很严格的配置且官方没有提供明确的文档来说明如何配置更多的是靠开源社区的讨论来解决问题。

View File

@ -16,7 +16,7 @@ slug: cover-generator
description: >- description: >-
本收集涵盖了多个封面生成工具和资源,旨在帮助用户快速创建美观且专业的封面设计。这些工具包括在线封面生成器、设计模板库以及自定义封面设计的技巧和指南。无论是用于书籍、报告、社交媒体还是其他用途,这些资源都能满足不同用户的需求,提升视觉呈现效果。 本收集涵盖了多个封面生成工具和资源,旨在帮助用户快速创建美观且专业的封面设计。这些工具包括在线封面生成器、设计模板库以及自定义封面设计的技巧和指南。无论是用于书籍、报告、社交媒体还是其他用途,这些资源都能满足不同用户的需求,提升视觉呈现效果。
date_created: 20250206 date_created: 20250206
date_modified: 20250302 date_modified: 20250306
finished: true finished: true
category: 软件 category: 软件
banner: >- banner: >-
@ -100,3 +100,15 @@ banner: >-
[GitHub 仓库](<https://github.com/youngle316/cover-paint>) [GitHub 仓库](<https://github.com/youngle316/cover-paint>)
![IMG-AEE6D7C35A6347C5F792B7FCC509C795](<https://pictures.kazoottt.top/2025/02/20250203-IMG-AEE6D7C35A6347C5F792B7FCC509C795.png>) ![IMG-AEE6D7C35A6347C5F792B7FCC509C795](<https://pictures.kazoottt.top/2025/02/20250203-IMG-AEE6D7C35A6347C5F792B7FCC509C795.png>)
## Imaker
20250305 更新 Imaker
[GitHub - slince-zero/IMaker: Create striking covers effortlessly with our easy-to-use IMaker.](<https://github.com/slince-zero/IMaker>)
[IMaker](<https://img-maker.vercel.app/>)
![IMG-59000B6CA38DF6FF4AB23AAA2920FF6F](</mdImages/IMG-59000B6CA38DF6FF4AB23AAA2920FF6F.png>)
字体大小不能调大很大