可能是兼容问题,用Node.js的path模块,path模块可以根据运行环境自动选对的分隔符: const path = require('path'); function compile(files, options) { const compilerOptions = { ...config.compilerOptions, ...options }; const host = ts.createCompilerHost(compilerOptions); host.writeFile = (fileName, contents) => { const isDts = fileName.endsWith('.d.ts'); const normalizedFileName = path.normalize(fileName); // 用 path.join 来构建路径,会自动处理路径分隔符 let outputPath = path.join(DIR, normalizedFileName); // 进行文件写入等操作 // ... }; // ... }