When attempting to launch a typescript application in Visual Studio Code (vs code) I'm getting the error "Cannot find module 'electron'". The project I'm trying to launch is black-screen which I have cloned from github.
This error is thrown on the following statement:
import {ipcMain, nativeImage} from "electron";
(on line 3 of the file https://github.com/shockone/black-screen/blob/master/src/main/Main.ts#l3)
I can transpile the application using the typescript-compiler (tsc) and no errors are generated, and can see the compiled javascript in the folder I expect (src/bin/). I can also start the application successfully using npm ("npm start").
Below are the relevant project configuration files:
src/tsconfig.json
{ "compilerOptions": { "target": "es6", "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, "moduleResolution": "node", "experimentalDecorators": true, "noEmitOnError": true, "pretty": true, "jsx": "react", "sourceMap": true, "outDir": "bin" } }.vscode/tasks.json file Note. Executing the equivalent command in a terminal "tsc --project src --moduleResolution node" generates the transpiled js code with no errors or warnings.
{ "version": "0.1.0", "command": "tsc", "isShellCommand": true, "showOutput": "silent", "args": ["--project", "src", "--moduleResolution", "node"], "problemMatcher": "$tsc" }.vscode/launch.json
{ "version": "0.2.0", "configurations": [ { "name": "Launch Black-Screen", "type": "node", "request": "launch", "program": "${workspaceRoot}/src/main/Main.ts", "stopOnEntry": false, "cwd": "${workspaceRoot}/src", "sourceMaps": true, "outDir": "${workspaceRoot}/src/bin" } ] }
Btw. the project structure is:
|.vscode/
|-- launch.json
|-- tasks.json
|decorators/
|...
|node_modules/
|-- bin/
|-- abbrev/
|-- acorn/
|README/
|-- <image files>
|src/
|-- bin/
|-- main/
|---- Main.ts
|---- Menu.ts
|...
|-- tsconfig.json
|...
|stylesheets/
|...
|test/
|...
|typings/
|...
|.babelrc
|.gitignore
|.npmrc
|...
|gulfile.bable.js
|package.json
|...
Any help would be appreciated :)
.d.ts) for Electron? Without that, the Typescript language service won't be able to tell that it exists.typings.json- try runningnpm install typings -gthentypings installin the project directory.npm install -g typings&typings install).error TS2300: Duplicate identifier <variable-name>for files "typings/browser/ambient/github-electron/github-electron.d.ts" and "typings/browser/ambient/electron/electron.d.ts".