electron 电子 typescript 应用程序因模块而崩溃

dy1byipe  于 2022-12-08  发布在  Electron
关注(0)|答案(1)|浏览(167)

我尝试使用Typescript构建一个在Electron上运行的客户端,但是,我收到以下错误:

tsconfig.json如下所示:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "useUnknownInCatchVariables": false,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "typeRoots": [
      "node_modules/@types",
      "src/types"
    ],
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

package.json是这样的:

{
  "name": "electron-quick-start-typescript",
  "version": "1.0.0",
  "description": "A minimal Electron application written with Typescript",
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "lint": "eslint -c .eslintrc --ext .ts ./src",
    "start": "npm run build && electron --no-sandbox ./dist/main.js"
  },
  "type": "module",
  "repository": "https://github.com/electron/electron-quick-start-typescript",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo",
    "typescript"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "@types/axios": "^0.14.0",
    "@types/electron": "^1.6.10",
    "@types/jquery": "^3.5.14",
    "@types/node": "^17.0.42",
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "electron": "^18.2.3",
    "eslint": "^7.32.0",
    "typescript": "^4.7.2"
  },
  "dependencies": {
    "axios": "^0.27.2",
    "jquery": "^3.6.0"
  }
}

无论我在tsconfig中选择什么模块类型,我都会遇到错误,这可能是由于在生成的JS文件中使用了require(我在浏览器中将其作为脚本使用),也可能是由于TS文件的编译过程。任何提示都很感激。提前感谢。

a11xaf1n

a11xaf1n1#

试使用**“模块”:“公用js”在tsconfig中,json和删除“类型”:“模块”**来自package.json

相关问题