vue.js - 缺少依赖项: aws-sdk in ./node_modules/node-pre-gyp/lib/info.js

标签 vue.js webpack electron-builder

我刚刚使用 vue-cli-plugin-electron-builder 构建了一个新的 Vue/Electron 应用程序它将利用 sqlite。

基本安装在开发过程中运行良好,直到我运行yarn add sqlite3。然后,我遇到了 aws-sdk 缺少依赖项错误。

研究表明这是一个 webpack 问题,可以使用 webpack externals 修复.

并且,来自 vue-electron-builder docs类似的解释和修复。

我已经根据此更新了我的 vue.config.js 和 webpack.config.js 文件,但几个小时后仍没有解决。

任何帮助或建议表示赞赏。谢谢。

[github 上的 webpack 节点外部线程] ( https://github.com/liady/webpack-node-externals ) Reading on webpack with backend apps

// vue.config.js
module.exports = {
  pluginOptions: {
    electronBuilder: {
      // List native deps here if they don't work
      externals: [ 'sqlite3' ],
      },
      // If you are using Yarn Workspaces, you may have multiple node_modules folders
      // List them all here so that VCP Electron Builder can find them
      nodeModulesPath: ['../../node_modules', './node_modules']
    }
  }
//webpack.config.js

// this file is for cases where we need to access the
// webpack config as a file when using CLI commands.
const nodeExternals = require('webpack-node-externals');

let service = process.VUE_CLI_SERVICE

if (!service || process.env.VUE_CLI_API_MODE) {
  const Service = require('./lib/Service')
  service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd())
  service.init(process.env.VUE_CLI_MODE || process.env.NODE_ENV)
}


module.exports = {
  service.resolveWebpackConfig(),
  externalsPresets: { node: true }, // in order to ignore built-in modules like path, fs, etc.
  externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
}
//package.json

{
  "name": "spectral",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "electron:build": "vue-cli-service electron:build",
    "electron:serve": "vue-cli-service electron:serve",
    "postinstall": "electron-builder install-app-deps",
    "postuninstall": "electron-builder install-app-deps"
  },
  "main": "background.js",
  "dependencies": {
    "axios": "^0.21.1",
    "core-js": "^3.6.5",
    "sqlite3": "^5.0.0",
    "vue": "^2.6.11",
    "vue-router": "^3.2.0",
    "webpack-node-externals": "^2.5.2"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.5.0",
    "@vue/cli-plugin-eslint": "^4.5.0",
    "@vue/cli-plugin-router": "^4.5.9",
    "@vue/cli-service": "^4.5.0",
    "babel-eslint": "^10.1.0",
    "electron": "^9.0.0",
    "electron-devtools-installer": "^3.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "vue-cli-plugin-electron-builder": "^2.0.0-rc.5",
    "vue-template-compiler": "^2.6.11"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}
//sqlite connection setup

const path = require('path');
const sqlite3 = require('sqlite3').verbose()
const dbPath = path.resolve('src/db/spectral.db');
let db

export const conn = () => {
  if (!db || !db.open) {
    db = new sqlite3.Database(dbPath)
  }
  return db
}

最佳答案

更多研究使我得出this线程解决了“sqlite3未定义错误”,但创建了一个新错误“require not find”,需要将nodeIntegration = true添加到vue.config.js中。

// working solution vue.config.js

module.exports = {
   pluginOptions: {
       electronBuilder: {
           externals: ['sqlite3'],
           nodeIntegration: true
         },
       }
};

其他引用资料 vue-electron-builder native modules

关于vue.js - 缺少依赖项: aws-sdk in ./node_modules/node-pre-gyp/lib/info.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65502079/

相关文章:

webpack - 在构建 Webpack 之前清除控制台

javascript - rails 6 : execute a JS function after rendering partial

windows-installer - 为 windows 创建应用程序安装程序 - Electron (electron-packager, electron-builder)

javascript - 我可以在 Vue 实例方法内部传播的 mapMutations 中使用 "this"吗?

javascript - Vue.js 在组件外设置数据

javascript - 使用带有 lodash 去抖动功能的 Vue.js 3

javascript - 参数数量不足或找不到条目

Electron 生成器和 Assets 文件

electron - 如何使用带有目标可移植 Electron 构建器?

javascript - 在 Laravel 上异步加载 Vue 组件