chrome-cookies-secure
chrome-cookies-secure copied to clipboard
After a clean install it says "Cannot find module 'keytar'"
npm i chrome-cookies-secure
The version is the latest, at the moment: 1.3.3
const cookies = await chrome.getCookiesPromised(url, 'puppeteer', 'Default');
Throws error
Error: Cannot find module 'keytar' Require stack:
- /Users/.../node_modules/chrome-cookies-secure/index.js
If I manually install keytar with npm i keytar then it works.
I am using Mac OS X Monterrey 12.3.1
And I see it is declared as an optional dependency. Perhaps it should be declared as a peer dependency?
What Node version? Seems OK to me running a very simplified version on Node 10.22.0.
keytar is only used in the context of darwin/mac in the codebase so it's redundant for other OS but it would be interesting to know which Node version, I'm also on Monterey 12.3.1
Oh sorry, I forgot to share the Node version. It is 16.14.0.
And it is so strange, now I created a new project from scratch with chrome-cookies-secure version 1.3.4 and it was working ...
I don't know the nitty gritty of how optional dependencies get handled but clearly here it did a strange job. I need to say that in the original project I had version 1.3.2 from the beginning, then I bumped into 1.3.3, whereas in this new project from scratch I started straight away from version 1.3.4.
Thanks for the support!
From the documentation I can find, optionalDependencies - if for some reason they fail to install - do not block the overall install pipeline and npm will carry on as if nothing happened:
https://docs.npmjs.com/cli/v7/configuring-npm/package-json#optionaldependencies
keytar is only required for process.platform === darwin so if it fails to install on windows or linux, that's fine, but when it fails on macOS that's just not going to work.
We also have win-dpapi where the same would apply to windows
I'm not sure on the technicalities of making certain dependencies required only on certain operating systems, but it seems safer at least to just move these to dependencies to eradicate the possibility of this happening.
I've created a draft PR for this here https://github.com/bertrandom/chrome-cookies-secure/pull/44#issue-1240593161 which should do the trick.
Turns out moving at least one of these (win-dpapi) to dependencies completely breaks the install on macOS. npm i complains that the required dependency does not fit the platform.
I've reverted to optionalDependencies.
@josep11 have you run into this problem since?
@rubengmurray I just checked and I cannot reproduce it with version 2.1.1.
Perhaps you can close it ;)
Thanks i'll close it