首页 文章

在Visual Studio代码中启动Typescript应用程序会抛出错误“找不到模块'electron'”

提问于
浏览
3

当尝试在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 回答

相关问题