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

"Can't resolve 'child_process'" error when using pino-sentry with Next.js #55

Open
grazianodev opened this issue Oct 10, 2022 · 8 comments

Comments

@grazianodev
Copy link

Hello,

I've installed pino-sentry in a Next.js project, however even by just importing from the package like this:

import pino from "pino"
import { createWriteStream } from "pino-sentry"
    
module.exports = pino({})

I get the following error:

./node_modules/@sentry/node/esm/integrations/context.js:2:0
Module not found: Can't resolve 'child_process'
    
Import trace for requested module:
./node_modules/@sentry/node/esm/sdk.js
./node_modules/@sentry/node/esm/index.js
./node_modules/pino-sentry/dist/transport.js
./node_modules/pino-sentry/dist/index.js
./logger/index.js
./helpers/fetch.js
./hooks/useViewer.js
./components/AppHeader/index.js
./pages/_app.js
    
https://nextjs.org/docs/messages/module-not-found

I would really like to try and use pino-sentry so any help would be appreciated! These are my package versions in case it matters:

"@sentry/nextjs": "^7.14.2"
"next": "^12.2.3",
"pino": "^8.6.1",
"pino-sentry": "^0.13.0",
"react": "^18.1.0",
"react-dom": "^18.1.0"
@glensc
Copy link
Collaborator

glensc commented Oct 10, 2022

  1. did you read the url your error message included?
  2. make standalone gist for reproducer

@grazianodev
Copy link
Author

Yes, I read the url. I guess you mean that the error is due to the Sentry package, however I only get that error when using pino-sentry, so I'm not sure... sorry if I made a mistake.

Anyway, I did create a reproduction. It's a basic create-next-app, to which I've only added the packages and logger code that I posted in my first message.

@glensc
Copy link
Collaborator

glensc commented Oct 11, 2022

I'm guessing you're trying to load pino to client side code:

and hence the error.

I'm not familiar with next.js, so it might take some time to for me to process it through

however, the problem could be also the way next.js does bundling. pino has some docs about it:

@glensc
Copy link
Collaborator

glensc commented Oct 11, 2022

you forgot to add instructions. and what's the reproduce steps there? yarn && yarn dev?

@grazianodev
Copy link
Author

I'm guessing you're trying to load pino to client side code

I do successfully use pino on the client side already and I do not get that error. The error only shows up as soon as I import createWriteStream from pino-sentry.

As for the repro, I use npm and do npm install and then npm run dev, which I think is the equivalent yarn && yarn dev. Once you launch the app you immediately get the error, but then if you go into logger.js (in the root folder) and comment out import { createWriteStream } from "pino-sentry", the error goes away, the page loads fine and in the console you should read This is a test log, which is a log I added in the homepage with pino's logger.info(which, incidentally, should demonstrate that pino works on the client).

Thanks for your help!

@glensc
Copy link
Collaborator

glensc commented Oct 11, 2022

no error here

➜ yarn && yarn dev
yarn install v1.22.19
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.34s.
yarn run v1.22.19
$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled client and server successfully in 654 ms (173 modules)

@sauldeleon
Copy link

sauldeleon commented Oct 20, 2022

Hello @glensc

I am currently facing the same issue. I have just added into my project pino-sentry and faced the same issue.

Maybe is a node.js related issue?

My versions are

    "@sentry/nextjs": "7.11.1",
    "pino-sentry": "0.13.0",
     "next": "12.2.5",
node version: v16.15.1

I will try to reproduce the repo or use the repo provided by @grazianodev

thanks!

EDIT: I have cloned the reproduction repo and I got the same issue

image

My steps:

  1. yarn, or npm i
  2. yarn dev or npm run dev
  3. go to localhost:3000
  4. 💥

Thanks!

EDIT 2: I wonder if this could be a dependencies version issue?

in transport.js you are referencing child_process

And I have spotted this issue from the original Sentry integration
getsentry/sentry-javascript#5787

@namdao2000
Copy link

namdao2000 commented Aug 23, 2023

Same issue here!
Using NextJS T3 Stack.

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