迁移至ESM-only包后VS Code调试器失效,报错无法获取node_modules路径
问题描述
将代码迁移至最新仅ESM包后,Visual Studio Code调试器停止工作。修改.swcrc和TypeScript配置后,调试器抛出错误:failed to get the node_modules path(无法获取node_modules路径)
环境配置
调试器配置(launch.json片段)
{ "name": "run api tests", "request": "launch", "type": "node", "skipFiles": ["<node_internals>/"], "program": "${workspaceFolder}/apps/api/node_modules/jest/bin/jest.js", "envFile": "${workspaceFolder}/apps/api/.env.test", "args": ["--config", "./apps/api/jest-api.config.mjs"], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" }
.swcrc配置
{ "$schema": "https://json.schemastore.org/swcrc", "module": { "type": "commonjs" }, "jsc": { "parser": { "syntax": "typescript", "dynamicImport": true, "tsx": false, "decorators": false }, "experimental": { "plugins": [["swc_mut_cjs_exports", {}]] }, "transform": { "legacyDecorator": true, "decoratorMetadata": false, "useDefineForClassFields": false }, "target": "es2020", "externalHelpers": true, "baseUrl": "." }, "sourceMaps": true }
tsconfig.json配置
{ "$schema": "https://json.schemastore.org/tsconfig", "compileOnSave": true, "compilerOptions": { "rootDir": "./src", "outDir": "dist", "module": "commonjs", "target": "ES2020", "moduleResolution": "node", "forceConsistentCasingInFileNames": true, "sourceMap": true, "allowJs": true, "resolveJsonModule": true, "removeComments": true, "alwaysStrict": true, "strictNullChecks": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true, "lib": ["es2020"], "skipLibCheck": true, "declaration": true, "declarationMap": true, "importsNotUsedAsValues": "error", "ignoreDeprecations": "5.0", "importHelpers": true, "isolatedModules": true }, "include": ["src/**/*"], "exclude": ["node_modules", "storage", "package.json", "test_assets"], "files": ["src/types.ts"], "ts-node": { "files": true } }
错误信息
● Test suite failed to run failed to get the node_modules path at Compiler.transformSync (../../node_modules/.pnpm/@swc+core@1.5.7_@swc+helpers@0.5.11/node_modules/@swc/core/index.js:244:29) at transformSync (../../node_modules/.pnpm/@swc+core@1.5.7_@swc+helpers@0.5.11/node_modules/@swc/core/index.js:351:21) at Object.process (../../node_modules/.pnpm/@swc+jest@0.2.36_@swc+core@1.5.7_@swc+helpers@0.5.11_/node_modules/@swc/jest/index.js:73:45) at ScriptTransformer.transformSource (../../node_modules/.pnpm/@jest+transform@29.7.0/node_modules/@jest/transform/build/ScriptTransformer.js:545:31) at ScriptTransformer._transformAndBuildScript (../../node_modules/.pnpm/@jest+transform@29.7.0/node_modules/@jest/transform/build/ScriptTransformer.js:674:40) at ScriptTransformer.transform (../../node_modules/.pnpm/@jest+transform@29.7.0/node_modules/@jest/transform/build/ScriptTransformer.js:726:19)
补充信息
- 使用pnpm管理同一文件夹下的多仓库,迁移前功能正常
- 已指定jest二进制文件的正确路径,疑问是否需要额外指定node_modules路径
内容的提问来源于stack exchange,提问作者alap
相关产品推荐
相关产品推荐

