提问:Electron启动不了(已解决)

2,018 阅读1分钟

问题

有没有人遇到过这个问题,如下图,运行npm run serve:test时,web服务启起来了,electron窗口就是不弹出来。不是代码问题,与同事的代码一模一样(刚从git上下下来)。

image.png

已尝试如下方法:

  1. 删除node_modules,重新npm i
  2. 切换阿里的npm源。
  3. 删除代码重新从git上拉。

一点头绪没有,头痛!!


2023-02-22 更新

终于找到一篇博文解决了我的问题。

cli-service 这里有一段代码会检查工程是用什么工具打管理依赖的

// node_modules/@vue/cli-service/lib/commands/serve.js
...

if (isFirstCompile) {
      isFirstCompile = false

      if (!isProduction) {
      
      // !!重点在这里!! 如果目录下存在 yarn.lock 就用yarn来build,按优先级 yarn > pnpm > npm 来选择构建工具
        const buildCommand = hasProjectYarn(api.getCwd()) ? `yarn build` : hasProjectPnpm(api.getCwd()) ? `pnpm run build` : `npm run build`
        console.log(`  Note that the development build is not optimized.`)
        console.log(`  To create a production build, run ${chalk.cyan(buildCommand)}.`)
      } else {
        console.log(`  App is served in production mode.`)
        console.log(`  Note this is for preview or E2E testing only.`)
      }
      console.log()

      if (args.open || projectDevServerOptions.open) {
        const pageUri = (projectDevServerOptions.openPage && typeof projectDevServerOptions.openPage === 'string')
          ? projectDevServerOptions.openPage
          : ''
        openBrowser(localUrlForBrowser + pageUri)
      }

...

知道问题所在,解决就简单了,两种办法。

  1. 删除yarn.lock
  2. 本机安装一下yarn

再次感谢这篇博文的博主。|

引用:

stackoverflow.com/questions/7…

www.cnblogs.com/zlc666/p/15…