vue-cli-service electron:serve Critical dependency: the request of a dependency is an expression


前置問題:

vue-cli-plugin-electron-builder preload build 無法加載問題

vue-cli-plugin-electron-builder build 時報 warning?

起因:

發現在electron的nodejs打包階段會報warning。

warning in ./node_modules/xxxxx
Critical dependency: the request of a dependency is an expression

造成結果:打包后的app無法使用。

過程2:

引用本地preload 且在開發模式下是可以加載的[這個是錯誤的配置方式-見前置問題]。修復打包配置后,發現這個問題。

原因:

build階段 ,nodejs 依賴包沒有被webpack打包識別。

解決方法:

在 vue.config.js 配置中 新增 "externals" 選項

module.exports = {
  pluginOptions: {
    electronBuilder: {
      externals: ["better-sqlite3", "ssh2", "...your_package"], // 新增你nodejs 依賴的項目
      preload: "preload.js",
    },
  }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM