Open anchann opened 7 years ago
Hmm. I was certain that this has been an issue for the longest time, but just now I restarted Sublime, and I can use go-to-definition on objects imported through the paths
alias. So the problem seems to be elsewhere, potentially related to the flakiness reported in #585 which I also experience.
Actually, this keeps happening. After everything runs fine for some time, the imports start going red-underlined, with "cannot find module xxx" on hover. I originally thought this happens when I switch git branches, but it just happened after a fresh sublime restart and no branch switching. How can I help debug this?
Is it possible that there's some limitation against handling multiple distinct typescript projects open in different sublime windows?
Hi @anchann, can you try using a fix I created at https://github.com/Microsoft/TypeScript-Sublime-Plugin/issues/585#issuecomment-292655670 And let me know if this solves your issue? If it does I'll try to publish a new version soon.
I've tried your fix but the problem persists. Seems that's only on the imports that use tsconfig paths.
I enabled logging. I'll try to post a log them next time the problem shows up.
Keeps happening with the local4.zip fix. I don't see any errors in the log:
2017-08-15 11:51:30,139: 140736961889216: WARNING: TypeScript plugin initialized.
I am facing this issue as well
I have these configs in the tsconfig
file:
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@src/*": ["./src/*"],
"@fixture/*": ["./test/fixture/*"]
},
...
}
Compiling tsc works just fine.
+1 for this issue.
+1
+1
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'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.
I have the same issue, but in my case problem is only present for test files, that is files with extension *.test.ts. I don't know why and have no solution so far. (Sublime Text 4, build 4113)
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...?
Same issue : Module not found and function definitions do not work with path aliases in Sublime but do work with relative path. Sublime issue only; compiles work fine. I'm using Sublime build 4143 and Typescript 4.5.2.
configurations:
{
"extends":"../../tsconfig.json",
"compilerOptions": {
"paths": {
"@idb-db-libx":["../lib/index"],
"@idb-db-lib*":["../lib/*"],
"@idb-db-lib-auth":["../lib/auth"],
"idb-db-lib-auth":["../lib/auth"],
"lettrywithoutdash":["../lib/auth"],
},
}
}
which extends:
{
"include":["lib/index.ts"],
"compilerOptions": {
"target": "ES2019",
"module": "commonjs",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": false,
"sourceMap": true,
"baseUrl": ".",
"paths": {
"@idb/*":["lib/*"],
"@idb-db-lib":["./db/lib/index.ts"],
"@idb-main-lib":["lib/index.ts"],
"@idb-main-lib/*":["lib/*"],
"@idb-main-lib-web":["lib/_index099"],
},
...
for me adding /* to my paths worked out just fine
this is previous to the fix/workaround getting this nasty "errors" in vscode
then i tried @marquizzo 's answer and
hope it helps somehow
TypeScript allows to modify module resolution using the
paths
configuration option on thecompilerOptions
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.