Reputation:
In a very large Mixed TS/JS project, using VSCode, I get the following errror.
Cannot find module 'shared/common/enums/httpMethod'.ts(2307)
The app builds successfully, and our pre-commit
hook, which runs eslint and tests isn't failing.
This happens in all .ts
files that I import .ts
files. I found a couple of answers on the matter, but none helped.
What I did so far includes:
vscode.d.ts
file from the node_modules with this command
ln -s /home/work/mymodule/node_modules/vscode.d.ts /usr/share/code/resources/app/out/vs/vscode.d.tsHere is the .tsconfig
file, that we use. Occasionally on the team, other members get this error, but after npm install
and restarting VSCode they are just fine.
{
"compilerOptions": {
"baseUrl": "./src",
"jsx": "react",
// Target latest version of ECMAScript.
"target": "esnext",
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
// Process & infer types from .js files.
"allowJs": true,
// Don't emit; allow Babel to transform files.
"noEmit": true,
// Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": true,
// Disallow features that require cross-file information for emit.
"isolatedModules": true,
// Import non-ES modules as default imports.
"esModuleInterop": true,
"skipLibCheck": true
},
// Import custom typings
"include": ["src/shared/**/*", "./typings"]
}
This is not a problem with .tsconfig
. I researched it, and we have the correct settings. Just putting it out there, for more info on the matter. If someone has the same problem as me, please post the answer or a link to it. Thanks!!
Upvotes: 22
Views: 30330
Reputation: 2090
I had this problem with a module I had created myself locally and had installed using npm i file://<PATH>
which creates a symlink to the local module.
The project built fine but VSCode's typescript language server could not seem to find the module.
Closing and reopening the folder did not resolve the problem.
I resolved it by going to an import declaration for the module and engaging autocomplete on the module name with ctrl+space to populate a list of modules starting with my actual module name. The module name popped up in the resulting list of suggestions (well, it was a list of one item) and the errors vanished immediately. OK. Whatever. Thanks Microsoft. So this is something else you can try.
Upvotes: -1
Reputation:
I found an answer to my question. In the tsconfig.json
. The problem was that in the include
section. I was having problems in the src/admin/..
.
So, I modified the file accordingly to include that. After that I don't have any problems:
"include": ["src/shared/**/*", "src/admin/**/* ", ./typings"]
So, the general answer I guess is to include every module, that you use aside from the general src
one.
Upvotes: 12