From 0aa30359aba4a30c686411fb8a122e2792771f37 Mon Sep 17 00:00:00 2001 From: digua Date: Tue, 19 May 2026 22:13:00 +0800 Subject: [PATCH] fix(cli): resolve ESM module resolution for tsx dev mode - Remove "type": "module" from apps/cli/package.json to avoid ESM/CJS interop issues with workspace packages in tsx dev mode - Configure tsup to output .mjs files (always treated as ESM by Node.js) - Rename bin entry from chatlab.js to chatlab.mjs - Change chatlab web default port to 3100 (serve keeps 3110) - Fix vite plugin: use pnpm instead of npx for tsx invocation --- apps/cli/bin/chatlab.js | 2 -- apps/cli/bin/chatlab.mjs | 2 ++ apps/cli/package.json | 7 +++---- apps/cli/tsup.config.ts | 1 + vite.web.config.mts | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) delete mode 100755 apps/cli/bin/chatlab.js create mode 100755 apps/cli/bin/chatlab.mjs diff --git a/apps/cli/bin/chatlab.js b/apps/cli/bin/chatlab.js deleted file mode 100755 index 11da8f35..00000000 --- a/apps/cli/bin/chatlab.js +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -import('../dist/cli.js').then((m) => m.run()) diff --git a/apps/cli/bin/chatlab.mjs b/apps/cli/bin/chatlab.mjs new file mode 100755 index 00000000..4f9d5f56 --- /dev/null +++ b/apps/cli/bin/chatlab.mjs @@ -0,0 +1,2 @@ +#!/usr/bin/env node +import('../dist/cli.mjs').then((m) => m.run()) diff --git a/apps/cli/package.json b/apps/cli/package.json index 59e488b7..e8adabb7 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -1,12 +1,11 @@ { "name": "chatlab-cli", "version": "0.1.0", - "description": "ChatLab CLI & Service - 聊天记录分析工具", - "type": "module", + "description": "ChatLab CLI & Service - Chat history analysis tool", "bin": { - "chatlab": "./bin/chatlab.js" + "chatlab": "./bin/chatlab.mjs" }, - "main": "./dist/index.js", + "main": "./dist/index.mjs", "files": [ "bin/", "dist/", diff --git a/apps/cli/tsup.config.ts b/apps/cli/tsup.config.ts index 1d6b2cb3..82410cce 100644 --- a/apps/cli/tsup.config.ts +++ b/apps/cli/tsup.config.ts @@ -7,6 +7,7 @@ export default defineConfig({ }, format: ['esm'], outDir: 'dist', + outExtension: () => ({ js: '.mjs' }), splitting: true, sourcemap: true, clean: true, diff --git a/vite.web.config.mts b/vite.web.config.mts index 6bc40af2..197eff6b 100644 --- a/vite.web.config.mts +++ b/vite.web.config.mts @@ -46,7 +46,7 @@ function chatlabServePlugin(): Plugin { const inUse = await isPortInUse(BACKEND_PORT) if (inUse) { - console.log(`[chatlab serve] 端口 ${BACKEND_PORT} 已在使用中,跳过启动`) + console.log(`[chatlab serve] Port ${BACKEND_PORT} already in use, skipping`) return } @@ -54,7 +54,7 @@ function chatlabServePlugin(): Plugin { const coreDir = resolve(__dirname, 'packages/core/src') const runtimeDir = resolve(__dirname, 'packages/node-runtime/src') serverProcess = spawn( - 'npx', + 'pnpm', [ 'tsx', 'watch',