Repository navigation
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
7.70.0
Framework Version
Next 13.5.2
Link to Sentry event
No response
SDK Setup
// This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: DNS_URL,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
replaysOnErrorSampleRate: 1.0,
// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,
// You can remove this option if you're not planning to use the Sentry Session Replay feature:
integrations: [
new Sentry.Replay({
// Additional Replay configuration goes in here, for example:
maskAllText: true,
blockAllMedia: true,
}),
],
});Steps to Reproduce
- update project from Next 13.4 to 13.5 with
yarn add next@latest react@latest react-dom@latest eslint-config-next@latest - remove and reinstall Sentry with
npx @sentry/wizard@latest -i nextjs - run dev server with
yarn dev
Expected Result
When navigating to localhost:3000, it displays a page.
Actual Result
When navigating to localhost:3000, it throws an error:
⨯ ./app/layout.tsx
Module not found: Can't resolve 'next/dist/client/components/request-async-storage'
I check in my node_modules directory and indeed request-async-storage is missing.
Reacted by Nicholas Haley, Dan and Tommy D. Rossi
Metadata
Metadata
Assignees
Labels
No labels
Projects
- StatusShow more project fieldsNo status

Activity
lforst commentedon Sep 22, 2023
Can you try deleting your .next folder and re-building? Thanks!
RilDev commentedon Sep 22, 2023
Hi, thanks for answering so quickly!
I already tried deleting the
.nextdirectory but it didn't fix my issue.And the
next buildcommand returns the same error:bautistaaa commentedon Sep 24, 2023
We are experiencing the same issues after bumping to 13.5.
Confirmed that all suggested steps did not work and that removing sentry from next config resolved the issue
related change: typehero/typehero@09ae9b7#diff-197cd8ca285a4abd2f21479e0bf6e36e90b08528fcd7f3bdbe8d1221897e377d
lforst commentedon Sep 25, 2023
@bautistaaa two things:
node -e "console.log(require.resolve('next/dist/client/components/request-async-storage'))"and share the output? Thanks!To me, something feels off. I cannot reproduce this yet we have a few reports of this. Our E2E tests also don't run into this issue.
I have a feeling that the people running into this have some sort of dirty state that the SDK doesn't particularily like (i.e. a state where
next/dist/client/components/request-async-storageis available viarequire.resolve).45 remaining items
rsolomon commentedon Oct 7, 2023
My hunch was that it had something to do with both the
esmandcjsbuilds being loaded and being unaware of the work the others had done (init in A, check init in B).It looks like the problem actually stems from a missing reference to root monorepo
node_moduleslocations inincomingConfig.resolve.modules, passed from Next.js tosrc/config/webpack.ts.In my project (using Yarn Workspaces), and I assume any other monorepo with default
resolvewebpack configs,incomingConfig.resolve.modulesis populated with these 2 values:'node_modules''/<absolute_path_to_monorepo>/packages/<project_with_next_js>'Sentry has some logic that turns (1) into
'/<absolute_path_to_monorepo>/packages/<project_with_next_js>/node_modules', but@sentry/nextjsin this case is actually installed in the Monorepo's rootnode_modulesdirectory, or'/<absolute_path_to_monorepo>/node_modules'. Since the resolution logic doesn't know modules can live here, it thinksrequest-async-moduledoesn't exist and errors out accordingly.There's probably a better way to accomplish this, but adding the following to my project's webpack config in
next.config.mjsfixes the problem and removes the console warning as expected:rsolomon commentedon Oct 7, 2023
@FaresKi If your project is a monorepo or uses otherwise an atypical structure for node_modules, the above will probably fix this issue for you.
lforst commentedon Oct 9, 2023
@rsolomon That is exactly what I am suspecting too, as per this comment. The thing is, we are already using
webpackOptions.resolve.modulesas base paths for the resolution algorithm. We should probably also add the root of the Next.js project there. Maybe Nx is messing withwebpackOptions.resolve.modules🤔.As for
This is not entirely correct. The resolution algorithm will look upwards in the folder tree, layer for layer, checking each
node_modulesfolder until it can find the requested module, which means the example you shared should actually work.rsolomon commentedon Oct 9, 2023
The logic you're talking about happens before and is therefore counteracted by this check.
requireResolveLocationis"/<absolute_path_to_monorepo>/node_modules/next/dist/client/components/request-async-storage.external.js", whileabsoluteWebpackResolvableModuleLocationsis["<absolute_path_to_monorepo>/packages/<project_with_next_js>/node_modules", "<absolute_path_to_monorepo>/packages/<project_with_next_js>"].requireResolveLocationdoes not start with either value inabsoluteWebpackResolvableModuleLocations, somoduleIsWebpackResolvablereturnsfalse, which makespotentialRequestAsyncStorageLocations.find(potentialLocation => moduleIsWebpackResolvable(potentialLocation))returnnull, ultimately being the return value ofgetRequestAsyncStorageModuleLocation.In other words, that line's intent (based on the comment) seems to be to filter out global node_modules locations, but it instead filters any node_modules location above the outermost location defined in
config.resolve.modules. In this case, that's the directory of the nextjs package itself.lforst commentedon Oct 10, 2023
@rsolomon Oh you're absolutely right! Thanks for putting so much thought into this! <3 I'll try to find the time to find a solution here this week!
rsolomon commentedon Oct 10, 2023
Happy to help 😄
lforst commentedon Oct 16, 2023
@rsolomon I opened a PR to fix all of this mess. I'd love to have you also take a look: #9259
rsolomon commentedon Oct 16, 2023
Thanks @lforst ! I'm at a conference all week but I'll do my best to check it out tonight or tomorrow night at the latest.
lforst commentedon Oct 17, 2023
Hi everybody, we just released version
7.74.1of the SDK which includes a fix for all of the problems discussed in this issue. Please try it out and let us know if the issue persists!jamespsterling commentedon Nov 2, 2023
Still seeing this on
7.77.0trying to run withts-node --esmlforst commentedon Nov 3, 2023
@jamespsterling Hi, can you please open a new issue with reproduction steps? Thanks!
oxygenart commentedon Nov 18, 2023
Hi, I temporarily resolved the issue by downgrading Next.js to version 13.3.4 from 13.4.1. The Sentry SDK versions I am using are:
"@sentry/nextjs": "^7.80.1",
"@sentry/utils": "^7.80.1",
I'm unsure if this is related to Next.js or Sentry, as Next.js version 13.4.1 was working fine for me before integrating Sentry.
I hope this information helps anyone facing a similar problem. Thanks!
remorses commentedon Dec 29, 2023
I had the same issue in a pnpm workspace, i fixed it by installing
@sentry/nextjsin the right app folder instead of root