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

Posted

技术标签:

【中文标题】缺少依赖项:./node_modules/node-pre-gyp/lib/info.js 中的 aws-sdk【英文标题】:Missing Dependency: aws-sdk in ./node_modules/node-pre-gyp/lib/info.js 【发布时间】:2021-04-06 16:03:31 【问题描述】:

我有一个使用 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


【问题讨论】:

【参考方案1】:

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

// working solution vue.config.js

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

其他参考 vue-electron-builder native modules

【讨论】:

以上是关于缺少依赖项:./node_modules/node-pre-gyp/lib/info.js 中的 aws-sdk的主要内容,如果未能解决你的问题,请参考以下文章

React Hook useEffect 缺少依赖项:'list'

Worldwind 缺少依赖项

React Hook useEffect 缺少依赖项

React Hook useEffect 缺少依赖项:'props'

React Hook useEffect 缺少依赖项:'History'

Eclipse 项目中缺少 Maven 依赖项