3

I am working on a Visual Studio Code extension, where I am using non-relative imports in typescript, for example:

import ModuleA from 'modules/ModuleA';

Where the actual folder to ModuleA is src/modules/ModuleA and the tsconfig.json is as follows, where I specify 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"
  ]
}

Everything compiles and builds just fine, however, when I attempt to launch the extension for testing, I get the error: Activating extension failed: Cannot find module 'modules/ModuleA'. My .vscode/launch.json file that I use to launch the extension looks like this:

// A launch configuration that compiles the extension and then opens it inside 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"
  }
  ]
}

How do I get non-relative paths working for developing vscode extensions?

girlcode
  • 3,155
  • 5
  • 27
  • 41
  • Why do you want to do "non-relative"? You probably should not use `baseUrl` for this. Try reference it directly using relative path: `./module/ModuleA` (assuming your code is under `src` – unional Apr 04 '17 at 05:50

1 Answers1

0

I have a similar experience, I reinstall the node, the same version, and the problem was solved.

I am using Mac, so:

sudo rm -rf /usr/local/lib/node_modules/npm
brew reinstall node

Reference: Error: Cannot find module '../lib/utils/unsupported.js' while using Ionic

Bill Chen
  • 1,699
  • 14
  • 24
  • I tested this on windows with `nvm install lts` but my error remains. Can you add some detail of the process of reinstallation? – Pablo LION Oct 28 '21 at 23:17
  • @Pablion, the above is for linux and macos, also it has been a while, would you mind to explain a little more about what kind of issue you have now? – Bill Chen Nov 02 '21 at 23:15
  • Thanks for the reply. I'm having the same error: `Activating extension 'X' failed: Cannot find module 'non/relative/path' Require stack: ...` Yet my tsconfig and launch.json was the same. It is said that tsconfig doesnt change anything of the bundling process [here in the official repo](https://github.com/microsoft/vscode-docs/issues/4906#issuecomment-955023025). – Pablo LION Nov 03 '21 at 00:21