TypeScript-Sublime-Plugin: tsconfig's compilerOptions' paths setting ignored

TypeScript allows to modify module resolution using the paths configuration option on the compilerOptions object. The mechanics of this are described in https://www.typescriptlang.org/docs/handbook/module-resolution.html. This feature is necessary for avoiding the relative path hell by aliasing the root of the current project, and importing files relative to that root.

Currently imports that contain an alias from the paths configuration are reported with the “Cannot find module” error, even though tsc resolves them correctly.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 17
  • Comments: 16 (1 by maintainers)

Most upvoted comments

+1 for this issue.

Has anyone ever gotten this to work? I define paths and if I use them e.g. in triple slash directives and hover over them, however, I get: Cannot find type definition file for ‘@yadayada/test’. So it seems the @yadayada is not even resolved in the first place…?

I had a similar problem where in tsconfig.json:

"paths": {
    "~Utils": ["src/utils"]
}

…would let me import from the “utils/index.ts” file, but it would give me an error in Sublime when importing modules in subfolders:

import { XXX } from "~Utils";    // <- Works
import { XXX } from "~Utils/subfolder";    // <- Does not work!

Funny thing is that the compiler wouldn’t complain, only Sublime would have problems finding it. However, adding a second alias in tsconfig.json would let me find modules both from "~Utils" and "~Utils/subfolder"

"paths": {
    "~Utils/*": ["src/utils/*"],
    "~Utils": ["src/utils"]
},

now they both work

import { XXX } from "~Utils";    // <- Works
import { XXX } from "~Utils/subfolder";    // <- Also works!

(using Sublime TypeScript plugin 3.7.3)

I am facing this issue as well

image

I have these configs in the tsconfig file:

"compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@src/*": ["./src/*"],
      "@fixture/*": ["./test/fixture/*"]
    },
	...
}

Compiling tsc works just fine.

I’m also experiencing this issue. I’m using Sublime Text 4 (build 4113) with the TypeScript plugin v4.3.2.

In my tsconfig.json:

"compilerOptions": {
	"moduleResolution": "node",
	"paths": {
		"@cipscis/csv": ["./src/csv.ts"]
	},

In one of my TypeScript files:

import { stringify, parse } from '@cipscis/csv';

Compiling this works absolutely fine, but within Sublime the '@cipscis/csv' string has a red underline, and hovering over it the error message is:

"Cannot find module '@cipscis/csv'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?"

The workarounds suggested in other comments in this thread haven’t helped me. I’m setting up my aliases this way so I can work with a Node.js package using Webpack using the same syntax as if it had been installed via npm.