Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vscode: error TS2307: Cannot find module 'vscode'

When compiling VSCode extension then typescript persistently complained

error TS2307: Cannot find module 'vscode'.

Installation npm install vscode or magic links never helped.

Strace provided:

stat("/home/work/mymodule/src/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d200) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode.ts", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode.tsx", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode.d.ts", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d230) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/@types", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/tma/work/qore/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/tma/work/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/tma/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/node_modules", 0x7ffe73f2d460)   = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/src/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d200) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode.js", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode.jsx", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d230) = -1 ENOENT (No such file or directory)

How to proceed?

like image 330
TMa Avatar asked Mar 20 '18 11:03

TMa


People also ask

Does vscode support TypeScript?

Visual Studio Code includes TypeScript language support but does not include the TypeScript compiler, tsc . You will need to install the TypeScript compiler either globally or in your workspace to transpile TypeScript source code to JavaScript ( tsc HelloWorld. ts ). You can test your install by checking the version.

Can not find module or its corresponding type declarations?

The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project. To solve the error, make sure to install the module and try setting moduleResolution to node in your tsconfig. json file.

Can not find module node JS?

If you are getting the "Cannot find module" error when trying to run a local file, make sure that the path you passed to the node command points to a file that exists. For example, if you run node src/index. js , make sure that the path src/index. js points to an existing file.


2 Answers

The solution

Run npm install to fix the issue.

Why?

Because there is "post install" script (node ./node_modules/vscode/bin/install) which fetch a vscode.d.ts according to the engine you're using in your project.

Detected VS Code engine version: ^1.6.0 Found minimal version that qualifies engine range: 1.6.0 Fetching vscode.d.ts from: https://raw.githubusercontent.com/Microsoft/vscode/e52fb0bc87e6f5c8f144e172639891d8d8c9aa55/src/vs/vscode.d.ts vscode.d.ts successfully installed!

source

like image 163
Mosh Feu Avatar answered Oct 09 '22 11:10

Mosh Feu


The solution is a link pointing to vscode.d.ts from node_modules directory.

ln -s /home/work/mymodule/node_modules/vscode.d.ts /usr/share/code/resources/app/out/vs/vscode.d.ts
like image 1
TMa Avatar answered Oct 09 '22 13:10

TMa