Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg Dependency missing #55

Open
LukasLoeffler opened this issue Sep 22, 2021 · 4 comments
Open

pg Dependency missing #55

LukasLoeffler opened this issue Sep 22, 2021 · 4 comments

Comments

@LukasLoeffler
Copy link

While setting up an empty project with pg-listen to do some testing I ran into an issue.

After installing pg listen via npm i pg-listen and starting a script with import createSubscriber from "pg-listen", node throws the folloing error:

internal/modules/cjs/loader.js:889
  const err = new Error(message); 
              ^

Error: Cannot find module 'pg'
Require stack:
- E:\Coding\pg-listener\node_modules\pg-listen\dist\index.js
- E:\Coding\pg-listener\node_modules\pg-listen\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (E:\Coding\pg-listener\node_modules\pg-listen\dist\index.js:56:10)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'E:\\Coding\\pg-listener\\node_modules\\pg-listen\\dist\\index.js',
    'E:\\Coding\\pg-listener\\node_modules\\pg-listen\\index.js'
  ]
}

After installing the package "pg" manually, the script started successfully.

Having a look into the package.json of pg-listen, "pg" only appears as peerDependency and devDependency.

@andywer
Copy link
Owner

andywer commented Sep 25, 2021

Hey Lukas. As you already pointed out, the dependency is not missing, it's a peer dependency.

The reason behind it is that you shall be able to use the pg version that you need and pg-listen will use what's there. The alternative would be that pg becomes a normal dependency, but then either your entire app will have to stick to the pg version that pg-listen requires (likely a deal-breaker for many projects) or you will end up with multiple pg instances in your dependency tree, each one in a different version, which can also lead to all kinds of subtle issues.

@andywer
Copy link
Owner

andywer commented Sep 25, 2021

It might make sense to change the readme, though:

- npm install pg-listen
+ npm install pg pg-listen

What do you think?

@LukasLoeffler
Copy link
Author

Hey Andy,
thanks for clarification.
I guess adding this to the readme will do the trick.
However, I would add an additional note that states the exact circumstances to prevent unnecessary pg installs.

@mirelon
Copy link

mirelon commented Dec 6, 2023

Is it really that any version of pg-listen works with any version of pg?
If not, then a compatibility matrix could be useful in the readme...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants