23

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?

1
  • 1
    I had the same problem. I deleted the node_modules and installed it again and it worked like charm.
    – Hamza Anis
    Aug 14, 2018 at 22:58

6 Answers 6

29

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

2
  • 3
    I had already run npm install but running it again did the trick
    – krubo
    Jun 26, 2019 at 15:25
  • Running npm post install does all that, but when it actually runs the node program above, it goes into this error "Error installing vscode.d.ts: Missing VSCode engine declaration in package.json." Went back and ran yo code again (since I had permission error) and it worked. this link helped understanding the cause of the issue.
    – shonjs
    Jul 2, 2019 at 17:20
2

I suggest that you close and open VS Code

2
  • I had randomly this issue and restart worked just fine.
    – Kert Kukk
    Jun 6 at 6:29
  • haha never thought this would work Nov 9 at 19:00
1

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
0

Update your Package.json "scripts" section to be:

"compile": "tsc -watch -p ./",
0

In my case, the reason is: can't load a module with a long path on Windows. Relate issue link: https://github.com/nodejs/node/issues/1990

So, after I upgrade nodejs v14.x to v15.x, the issue was gone.

0

If you get this error when trying to create a webview for a vsCode extension, check that you are doing it under the client folder and no the server folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.