當試圖在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