Home > Enterprise >  sqlite3 node_module bloat
sqlite3 node_module bloat

Time:11-17

A fresh install of Electron (v21.2.2 win32-x64) using npm to install sqlite3 node package v5.1.2 shows when I open the node_module folder 101 items. I deleted them all except for sqlite3 and console now shows dependency errors :

Uncaught Error: Cannot find module '@mapbox/node-pre-gyp'
Require stack:
- D:\Electron\resources\app\node_modules\sqlite3\lib\sqlite3-binding.js
- D:\Electron\resources\app\node_modules\sqlite3\lib\sqlite3.js
.....

I understand there are dependencies from the sqlite3 package.json, specifically node-pre-gyp. However out of 101 packages it wants 28 just to run sqlite3:

  • @mapbox/node-pre-gyp
  • abbrev
  • ansi-regex
  • aproba
  • are-we-there-yet
  • color-support
  • console-control-strings
  • delegates
  • detect-libc
  • emoji-regex
  • gauge
  • has-unicode
  • inherits
  • is-fullwidth-code-point
  • lru-cache
  • nopt
  • npmlog
  • object-assign
  • readable-stream
  • semver
  • set-blocking
  • signal-exit
  • sqlite3
  • string-width
  • strip-ansi
  • util-deprecate
  • wide-align
  • yallist

I wanted sqlite3 for Electron and was expecting one module. Are they all needed?

CodePudding user response:

The unsatisfying answer is Yes.

... unsure if they are all truly needed?

The short explanation is that npm is designed to work this way; different packages have their own dependency tree, which have their own, and so on...

As you have found, doing this will break packages:

I deleted them all except for sqlite3 and console shows dependency errors

It is wise to leave the node_modules/ directory alone

Side Note

As you use more external libraries, you may begin to see the number of dependencies doesn't continue to grow at the same rate. This is because some libraries will have the similar (or the same) underlying dependency tree.

This is where package managers really come into their own.

  • Related