chrome-cookies-secure icon indicating copy to clipboard operation
chrome-cookies-secure copied to clipboard

After a clean install it says "Cannot find module 'keytar'"

Open josep11 opened this issue 3 years ago • 6 comments

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

josep11 avatar May 13 '22 09:05 josep11

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?

josep11 avatar May 13 '22 09:05 josep11

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

rubengmurray avatar May 14 '22 16:05 rubengmurray

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!

josep11 avatar May 16 '22 08:05 josep11

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.

rubengmurray avatar May 18 '22 22:05 rubengmurray

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.

rubengmurray avatar May 18 '22 22:05 rubengmurray

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.

rubengmurray avatar Jun 04 '22 20:06 rubengmurray

@josep11 have you run into this problem since?

rubengmurray avatar Sep 03 '23 10:09 rubengmurray

@rubengmurray I just checked and I cannot reproduce it with version 2.1.1. Perhaps you can close it ;)

josep11 avatar Nov 01 '23 20:11 josep11

Thanks i'll close it

rubengmurray avatar Nov 01 '23 23:11 rubengmurray