-1

I have a docker container that combines 2 node projects into one. Project A is the statsd project and project B is a postgres backend project that writes to a postgres database using the npm package pg. I have both A and B in a 2 separate repos. Then I copy them into the docker image separately like the following in the Dockerfile:

COPY ./statsd/ /opt/statsd/
COPY ./postgres-backend/ /opt/statsd/postgres-backend/

Then I copy the javascript from postgres-backend to the folder /opt/statsd/backends/ inside docker. At this stage, I can do npm install inside /opt/statsd directory with its own package.json specification. However, my postgres-backend repo has its own package.json file that specifies what dependencies it requires (in this case pg). I tried switching to the /opt/statsd/postgres-backend directory and doing npm install. That only installed in the sub-directory. And when I run statsd.js in the /opt/statsd directory it complained that the module pg was not found.

How can I solve this one project with 2 package.json problem?

breezymri
  • 3,975
  • 8
  • 31
  • 65
  • npm install pg@x.x didnt work??? – lopezdp Aug 15 '17 at 04:48
  • 2
    @lopezdp That works but it feels like a hack because the package.json for the postgres-backend is circumvented. What if in the future another dependency is added to the postgres-backend project? I'm wondering if there is a better solution to this situation. – breezymri Aug 15 '17 at 15:56
  • 1
    That is your solution. The work you have to do is debug and update new versions with dependencies to old libraries when they start deprecating old functionality which they no longer support. Also make sure to add --save at the end on the npm command to make sure it saves to your project's app! – lopezdp Aug 16 '17 at 01:03
  • let me know if that answer solves your problems. It's not a hack, it's the way you make it work in an environment where packages are being constantly extended, updated, improved, and worked on. Sometimes versions have deprecated functionality that breaks your app. – lopezdp Aug 16 '17 at 01:12
  • Are you using a framework like ExpressJS? – lopezdp Aug 16 '17 at 01:13
  • What do you end up discovering? – lopezdp Sep 06 '17 at 02:38

1 Answers1

1

The issue is that your app depends on a specific version of the pg package. I would find the version you need and run:

npm install pg@x.x --save

Where x.x is the version your app is dependent on to run and --save to ensure your dependencies are updated in your package.json file.

You just need to tell your app which version your app is dependent on. (Basically)...

lopezdp
  • 1,538
  • 3
  • 21
  • 38