当前位置: 首页 > 知识库问答 >
问题:

在Visual Studio代码中启动Typescript应用程序时引发错误“找不到模块'Electon'”

司寇瑾瑜
2023-03-14

当试图在Visual Studio代码(vs代码)中启动typescript应用程序时,我得到的错误是“无法找到模块'Elector'”。我试图启动的项目是黑屏的,我从GitHub克隆出来的。

从“电子”导入{ipcMain,nativeImage};

(在文件https://github.com/shockone/black-screen/blob/master/src/main/main.ts#l3的第3行)

我可以使用typescript-compiler(tsc)transpile应用程序,不会生成错误,并且可以在我期望的文件夹(src/bin/)中看到编译后的javascript。我也可以使用npm成功启动应用程序(“npm启动”)。

以下是相关的项目配置文件:

>

  • 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"
      }
    }
    
    {
        "version": "0.1.0",
        "command": "tsc",
        "isShellCommand": true,
        "showOutput": "silent",
        "args": ["--project", "src", "--moduleResolution", "node"],
        "problemMatcher": "$tsc"
    }
    
    {
        "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
    |...
    
  • 共有1个答案

    欧照
    2023-03-14

    我修复了调试器无法识别电子模块的错误。问题是由于电子应用程序在我的应用程序启动之前没有启动。

    我发现了一个stackoverflow问题,并链接了解决这个问题的博客文章-用Visual Studio代码调试Electron-Atom脚本/
    http://www.mylifeforthecode.com/a-better-way-to-launch-electron-from-visual-Studio-Code/

    在我的“launch.json”文件中添加“runtimeexecutable”:“${workspaceRoot}/node_modules/electron-prebuilt/dist/electront”行,在调试器启动之前启动了电子。

    我的最后一个“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",
                "runtimeExecutable": "${workspaceRoot}/node_modules/electron-prebuilt/dist/electron"
            }
        ]
    }
    

    调试器正在我设置的断点处停止。我注意到使用调试器electron的性能要慢得多,但这是我将解决的另一个问题:)

     类似资料:
    • 我花了半天时间试图为此找到一个可行的解决方案,但要么我做错了一切,要么什么都不适合我。我是Java和JavaFX的新手。 我在Windows上使用VSCode,并且安装了“Extension Pack for Java”和“Maven for Java”扩展,我使用JAVAFX原型作为构建方法创建了一个项目。 生成了一个示例项目,我运行它没有问题,甚至没有添加带有“VMargs”等的“launch

    • 问题内容: 我正在开发使用firebase admin的简单React应用程序。 我已经通过使用create react app生成了react应用程序。 然后,我通过使用以下npm命令进行了安装: 在我中,我添加了此导入: 当我使用命令启动并打开页面时,出现以下错误: 为什么会这样呢?我错过了什么? 问题答案: 管理员SDK不能在客户端环境中使用。包括网络浏览器。Admin SDK可以并且应该仅

    • 以下是错误: 下面是我的pom.xml文件: 这是我的主课:

    • 我正在尝试使用简单的spring启动应用程序。我在ApplicationContext上启动应用程序时遇到问题。 2017-04-26 11:17:31.101警告14528---[main]s.c.a.AnnotationConfigApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org。springframework。豆。工厂未满足的PendencyExcepti

    • 行动: 考虑在配置中定义一个名为entityManagerFactory的bean。 下面是代码。应用JAVA 主控制器。JAVA AppUser。JAVA 用户存储库。JAVA 波姆。xml application.properties