当尝试在Visual Studio代码(vs代码)中启动打字稿应用程序时,我试图启动'm getting the error 1030251 . The project I'是我从github克隆的black-screen .
以下语句抛出此错误:
import {ipcMain, nativeImage} from "electron";
(在文件https://github.com/shockone/black-screen/blob/master/src/main/Main.ts#l3的第3行)
我可以使用typescript-compiler(tsc)来转换应用程序,并且不会生成错误,并且可以在我期望的文件夹中看到已编译的javascript(src / bin /) . 我也可以使用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 node”中执行等效命令会生成没有错误或警告的已转换的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
|...
任何帮助,将不胜感激 :)
2 回答
我修正了错误,电子模块未被调试器识别 . 问题是由于电子应用程序在我的应用程序启动之前没有启动 .
我找到了一个stackoverflow问题和链接的博客文章,解决了这个问题 - Debugging Electron-Atom script with Visual Studio Code /
http://www.mylifeforthecode.com/a-better-way-to-launch-electron-from-visual-studio-code/
在调试器启动之前,将
"runtimeExecutable": "${workspaceRoot}/node_modules/electron-prebuilt/dist/electron"
行添加到我的"launch.json"文件中 .我最后的“launch.json”文件是:
调试器在我设置的断点处停止 . 我注意到使用调试器时电子的性能要慢很多,但这是另一个问题我将通过:)
该项目包含https://github.com/shockone/black-screen/blob/master/typings/main/ambient/github-electron/github-electron.d.ts,并声明该模块:https://github.com/shockone/black-screen/blob/master/typings/main/ambient/github-electron/github-electron.d.ts#L1884
怀疑错误的行:
改成 :
因为这在过去对我有用 .