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

keyv doesn't work in pnpm monorepo #70

Closed
dandv opened this issue Jan 4, 2019 · 5 comments
Closed

keyv doesn't work in pnpm monorepo #70

dandv opened this issue Jan 4, 2019 · 5 comments

Comments

@dandv
Copy link
Contributor

dandv commented Jan 4, 2019

Trying to use keyv and @keyv/mongo works with npm (duh), pnpm, but not if the project is a pnpm workspace. The error is "Error: Cannot find module '@keyv/mongo'".

Repro repo at https://github.com/dandv/pnpm-monorepo-keyv

Any idea what might cause this?

@lukechilds
Copy link
Contributor

Sorry, I'm really not familiar with pnpm.

One idea might be that I try and auto-detect the correct module based on the connection string. Sounds like this might be where it's going wrong.

I see you're using @keyv/mongo. Could you try manually passing in the storage adapter instead of letting Keyv infer it from your connection string.

E.g instead of:

const Keyv = require('keyv');

const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname');

Can you try:

const Keyv = require('keyv');
const KeyvMongo = require('@keyv/mongo');

const keyvMongo = new KeyvMongo('mongodb://user:pass@localhost:27017/dbname');
const keyv = new Keyv({ store: keyvMongo });

@dandv
Copy link
Contributor Author

dandv commented Jan 5, 2019

Yes, requiring @keyv/mongo explicitly worked!

@lukechilds
Copy link
Contributor

Ahh, so seems like pnpm is hijacking the Node.js dependency resolution algorithm somehow.

I wouldn't really consider this a bug in Keyv so I'll close this issue. Glad you got it sorted though. Thanks for reporting, hopefully this issue will help anyone else who gets stuck using Keyv with pnpm. 👍

@zkochan
Copy link

zkochan commented Jan 5, 2019

This issue should be solved with optional peer dependencies. We don't support them yet but we will. (I believe Yarn already has support in the latest version)

You basically have to add this to the package.json of keyv:

"peerDependencies": {
  "@keyv/mongo": "1"
},
"peerDependenciesMeta": {
  "@keyv/mongo": {
    "optional": true
  }
}

cc @arcanis

@matzkoh
Copy link

matzkoh commented Dec 13, 2022

I saw this error when I deployed my app to vercel.
I simply added one line and it worked without any other changes.

import Keyv from 'keyv'
import '@keyv/mongo' // <===

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

4 participants