简体   繁体   中英

How to use dependency of dependency in node.js

Situation: I have a node.js library that uses sequelize to define and export models. In my backend app I use this library. This backend app also needs to access to stuff exported by sequelize .

Question: What is the correct way of accessing sequelize from my backend app?

  • I can add sequelize into my backend app's dependencies in package.json, but then if versions don't match some weird things start to happen. This is also hard to maintain, as I have many backend apps and I always have to manually keep track of versions.
  • I can access it via import sequelize from "boxlock-common-server/node_modules/sequelize";
  • ?

What is the correct way of doing this?

You can try using package aliases

"dependencies": {
   "pkg1": "npm:sequelize@6.23.0",
   "pkg2": "npm:sequelize@6.22.0"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM