Currently, I am in the process of developing a Visual Studio Code extension. In this project, I have opted to utilize non-relative imports in TypeScript. For instance:
import ModuleA from 'modules/ModuleA';
The actual location of the folder for ModuleA
is src/modules/ModuleA
. To ensure the proper configuration, my tsconfig.json
file includes setting src
as the baseUrl
:
{
"compilerOptions": {
"baseUrl": "./src",
"module": "commonjs",
"target": "es6",
"outDir": "out",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"lib": [
"es6"
],
"sourceMap": true,
"strictNullChecks": true,
"experimentalDecorators": true,
"moduleResolution": "node"
},
"exclude": [
"node_modules",
".vscode-test"
]
}
While everything compiles and builds without issues, upon testing the extension, I encounter an error:
Activating extension failed: Cannot find module 'modules/ModuleA'
. My .vscode/launch.json
file used for launching the extension appears as follows:
// This configuration compiles the extension and then launches it in a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out"],
"preLaunchTask": "build",
"internalConsoleOptions" : "openOnSessionStart"
}
]
}
I am seeking guidance on how to successfully implement non-relative paths for vscode extensions development.