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

Cannot find module 'cookie' #3060

Closed
4 of 8 tasks
kbrownlees opened this issue Nov 19, 2020 · 9 comments · Fixed by #3210
Closed
4 of 8 tasks

Cannot find module 'cookie' #3060

kbrownlees opened this issue Nov 19, 2020 · 9 comments · Fixed by #3210

Comments

@kbrownlees
Copy link

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

5.27.4
Node v10.21.0

Description

I am getting errors because 'cookie' is failing to import. I have multiple dependencies which all depend on cookie and deployment is done via npm ci which means that 'cookie' does not end up at the top level of node_modules. It only exists within @sentry/node. Either dynamicRequire is failing to handle a non top level package, or it is failing to handle the fact the cookie dependencies is in @sentry/node not @sentry/utils.

> require('@sentry/node/node_modules/cookie')
{ parse: [Function: parse], serialize: [Function: serialize] }
> require('cookie')
Thrown:
{ Error: Cannot find module 'cookie'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18) code: 'MODULE_NOT_FOUND' }
root@b84575c0d6e0:/app# find node_modules/| grep "/cookie/"
node_modules/express/node_modules/cookie/LICENSE
node_modules/express/node_modules/cookie/package.json
node_modules/express/node_modules/cookie/HISTORY.md
node_modules/express/node_modules/cookie/README.md
node_modules/express/node_modules/cookie/index.js
node_modules/elastic-apm-node/node_modules/cookie/LICENSE
node_modules/elastic-apm-node/node_modules/cookie/package.json
node_modules/elastic-apm-node/node_modules/cookie/HISTORY.md
node_modules/elastic-apm-node/node_modules/cookie/README.md
node_modules/elastic-apm-node/node_modules/cookie/index.js
node_modules/cookie-parser/node_modules/cookie/LICENSE
node_modules/cookie-parser/node_modules/cookie/package.json
node_modules/cookie-parser/node_modules/cookie/HISTORY.md
node_modules/cookie-parser/node_modules/cookie/README.md
node_modules/cookie-parser/node_modules/cookie/index.js
node_modules/@sentry/node/node_modules/cookie/LICENSE
node_modules/@sentry/node/node_modules/cookie/package.json
node_modules/@sentry/node/node_modules/cookie/HISTORY.md
node_modules/@sentry/node/node_modules/cookie/README.md
node_modules/@sentry/node/node_modules/cookie/index.js
@lobsterkatie
Copy link
Member

Sorry, not sure I follow. How does @sentry/utils come into it?

@kbrownlees
Copy link
Author

Sorry, not sure I follow. How does @sentry/utils come into it?

The code which assumes it can dynamically import cookie is here: https://github.com/getsentry/sentry-javascript/blob/master/packages/utils/src/node.ts#L94. Cookie is a dependency of @sentry/node (https://github.com/getsentry/sentry-javascript/blob/master/packages/node/package.json#L24) but not @sentry/utils (https://github.com/getsentry/sentry-javascript/blob/master/packages/utils/package.json).

I am not entirely clear about how the magic that allows require to import different versions of packages work, but it seems like the setup you have here is not one of them for some reason..

@lobsterkatie
Copy link
Member

Ah, shoot, dynamicRequire - right, thanks. Must have skipped right over that when I read it the first time.

The good news is, I'm pretty sure a refactor (for other reasons) which is in our backlog will fix this. The bad news is, I can't give you a specific timeline on when it's going to ship. I'll give it a look next week and see if it seems like it might be a relatively quick fix.

@kbrownlees
Copy link
Author

There is no hurry from my side, I have fixed it by adding cookie to my top level dependencies for the time being and it appears to be working fine.

@lobsterkatie
Copy link
Member

Great, thanks. Will let you know once I do something.

@P4sca1
Copy link

P4sca1 commented Jan 1, 2021

This error also occurs when using @sentry/serverless. You have to manually add cookies to the dependencies to resolve this issue.

@kamilogorek
Copy link
Contributor

Related #2971

@lobsterkatie
Copy link
Member

@P4sca1 @kbrownlees This should be fixed once #3210 is released. Please let me know if you're still running into trouble.

@kamilogorek
Copy link
Contributor

6.0.4 is coming in few moments. Thanks for your patience.

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