当试图在Visual Studio代码(vs代码)中启动打印应用程序时,出现错误“无法找到模块电子”。我试图启动的项目是我从github克隆的。在Visual Studio中启动Typescript应用程序代码抛出错误“无法找到模块电子”
此错误是扔在了下面的语句:
import {ipcMain, nativeImage} from "electron";
(在文件https://github.com/shockone/black-screen/blob/master/src/main/Main.ts#l3的第3行)
我可以使用打字稿编译器(TSC)和transpile的申请会生成错误,并且可以在我期望的文件夹(src/bin /)中看到编译后的javascript。我也可以使用npm(“npm start”)成功启动应用程序。
下面是相关项目的配置文件:
的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文件 注意。在终端“tsc --project src --moduleResolution节点”中执行等效命令会生成没有错误或警告的经过转换的js代码。
{ "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" } ] }
顺便说一句。项目结构是:
|.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
|...
任何帮助,将不胜感激:)
工作的你有一个Electron的定义文件('.d.ts')吗?如果没有这个,Typescript语言服务将无法辨别它是否存在。 –
事实上,我刚刚注意到,你克隆的repo有一个' typings.json' - 尝试运行'npm install typings -g'然后'typings install'到项目目录 –
谢谢Joe。当我看到Basarat的回答后,我检查并看到“typings”目录已经存在于存储库文件中。确实尝试安装类型('npm我nstall -g typings'&'typings install')。 – Michael