在 VSCode 中调试 lerna-typescript 项目
Debugging a lerna-typescript project in VSCode
我正在尝试使用 lerna+typescript 构建一个 monorepo,我正在使用这个 repo 作为开始:https://github.com/Izhaki/mono.ts
我想要实现的是调试 visual studio 代码中的代码。我试过像这样添加 launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug",
"preLaunchTask": "npm: build",
"program": "${workspaceFolder}/packages/line/src/index.ts",
"sourceMaps": true,
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [
"${workspaceFolder}/packages/line/dist/**/*.js"
]
}
]
}
我在导入和使用时遇到了一些错误:
/Users/davidericci/Desktop/mono.ts-master/packages/line/dist/index.js:1
(function (exports, require, module, __filename, __dirname) { import { getDistance } from '@geo/point';
^
SyntaxError: Unexpected token {
所以我在 tsconfig.build.json
(包内)中进行了更改:
"target": "es2017",
"module": "commonjs",
和 tsconfig.base.json
内(总是在包内):
{
"compilerOptions": {
"lib": ["es2015", "es2016", "dom", "es2017", "es6", "es5"],
"noUnusedLocals": true
}
}
但我仍然得到:
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module '@geo/point'
作为错误,我认为是因为在代码内部(即使在 JS 代码中)导入仍然指向打字稿。我这里可能是错的。
所有其他设置都是该项目的默认设置。
可以和tsconfig-paths
有关系吗?或者只是 launch.json?
中的一些设置
非常感谢你们
不幸的是,我不得不放弃使用 https://github.com/Izhaki/mono.ts
的想法
使用标准配置文件,我成功地使用 lerna 进行了调试,甚至离线使用了无服务器。
这是我的文件:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug ms-locations",
"preLaunchTask": "npm: lerna-tsc",
"program": "${workspaceFolder}/packages/ms-locations/lib/sample.js",
"cwd": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/packages/ms-locations/**/*.js"
],
"protocol": "inspector",
}
tsconfig
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [
"es6"
], /* Specify library files to be included in the compilation. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
/* Strict Type-Checking Options */
"strict": false, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"incremental": true
},
"exclude": [
"node_modules",
"**/*.spec.ts",
"packages/ms-api/test/*.ts"
]
}
在我的包文件夹里面,如果你需要使用serverless
这是 tsconfig
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"moduleResolution": "node",
"noUnusedLocals": false,
"noUnusedParameters": false,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"target": "es2017",
"esModuleInterop": true,
"incremental": false
},
"include": [
"./src"
]
}
我会将此标记为已接受的答案,即使这个问题并不完全令人信服,但这是我的解决方案。
希望对某人有所帮助
我似乎用一种稍微不同的方法来工作,避免使用 lerna(尽管是使用 Lerna 的 monorepo)。
这是我的 launch.json
:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Test show",
"type": "node",
"request": "launch",
"address": "localhost",
"protocol": "inspector",
"cwd": "${workspaceFolder}/services/shows",
"program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
"args": [
"invoke",
"local",
"-f",
"get",
"-p",
"./mocks/get-event.json"
],
"outFiles": [
"${workspaceFolder}/services/shows/.webpack/service/src/get.js"
],
"autoAttachChildProcesses": true
}
]
}
还有我的tsconfig.json
:
{
"compilerOptions": {
"lib": ["es2017"],
"moduleResolution": "node",
"noUnusedLocals": true,
"strictNullChecks": true,
"preserveConstEnums": true,
"declaration": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"noImplicitReturns": true,
"strict": true,
"sourceMap": true,
"target": "es2017",
"outDir": ".build"
},
"exclude": ["node_modules"]
}
希望这对您或其他人有所帮助!
我正在尝试使用 lerna+typescript 构建一个 monorepo,我正在使用这个 repo 作为开始:https://github.com/Izhaki/mono.ts
我想要实现的是调试 visual studio 代码中的代码。我试过像这样添加 launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug",
"preLaunchTask": "npm: build",
"program": "${workspaceFolder}/packages/line/src/index.ts",
"sourceMaps": true,
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [
"${workspaceFolder}/packages/line/dist/**/*.js"
]
}
]
}
我在导入和使用时遇到了一些错误:
/Users/davidericci/Desktop/mono.ts-master/packages/line/dist/index.js:1
(function (exports, require, module, __filename, __dirname) { import { getDistance } from '@geo/point';
^
SyntaxError: Unexpected token {
所以我在 tsconfig.build.json
(包内)中进行了更改:
"target": "es2017",
"module": "commonjs",
和 tsconfig.base.json
内(总是在包内):
{
"compilerOptions": {
"lib": ["es2015", "es2016", "dom", "es2017", "es6", "es5"],
"noUnusedLocals": true
}
}
但我仍然得到:
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module '@geo/point'
作为错误,我认为是因为在代码内部(即使在 JS 代码中)导入仍然指向打字稿。我这里可能是错的。
所有其他设置都是该项目的默认设置。
可以和tsconfig-paths
有关系吗?或者只是 launch.json?
非常感谢你们
不幸的是,我不得不放弃使用 https://github.com/Izhaki/mono.ts
的想法使用标准配置文件,我成功地使用 lerna 进行了调试,甚至离线使用了无服务器。
这是我的文件:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug ms-locations",
"preLaunchTask": "npm: lerna-tsc",
"program": "${workspaceFolder}/packages/ms-locations/lib/sample.js",
"cwd": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/packages/ms-locations/**/*.js"
],
"protocol": "inspector",
}
tsconfig
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [
"es6"
], /* Specify library files to be included in the compilation. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
/* Strict Type-Checking Options */
"strict": false, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"incremental": true
},
"exclude": [
"node_modules",
"**/*.spec.ts",
"packages/ms-api/test/*.ts"
]
}
在我的包文件夹里面,如果你需要使用serverless 这是 tsconfig
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"moduleResolution": "node",
"noUnusedLocals": false,
"noUnusedParameters": false,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"target": "es2017",
"esModuleInterop": true,
"incremental": false
},
"include": [
"./src"
]
}
我会将此标记为已接受的答案,即使这个问题并不完全令人信服,但这是我的解决方案。
希望对某人有所帮助
我似乎用一种稍微不同的方法来工作,避免使用 lerna(尽管是使用 Lerna 的 monorepo)。
这是我的 launch.json
:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Test show",
"type": "node",
"request": "launch",
"address": "localhost",
"protocol": "inspector",
"cwd": "${workspaceFolder}/services/shows",
"program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
"args": [
"invoke",
"local",
"-f",
"get",
"-p",
"./mocks/get-event.json"
],
"outFiles": [
"${workspaceFolder}/services/shows/.webpack/service/src/get.js"
],
"autoAttachChildProcesses": true
}
]
}
还有我的tsconfig.json
:
{
"compilerOptions": {
"lib": ["es2017"],
"moduleResolution": "node",
"noUnusedLocals": true,
"strictNullChecks": true,
"preserveConstEnums": true,
"declaration": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"noImplicitReturns": true,
"strict": true,
"sourceMap": true,
"target": "es2017",
"outDir": ".build"
},
"exclude": ["node_modules"]
}
希望这对您或其他人有所帮助!