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

[Windows] TypeError when running Next.js app with middleware and latest @sentry/nextjs package #6858

Closed
3 tasks done
josh- opened this issue Jan 19, 2023 · 19 comments · Fixed by #6866
Closed
3 tasks done

Comments

@josh-
Copy link

josh- commented Jan 19, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/angular

SDK Version

7.31.1

Framework Version

@sentry/nextjs 7.31.1

Link to Sentry event

https://sentry.io/organizations/triton-digital-canada-inc/issues/3883394829/

SDK Setup

The sample repro repository uses the following values, where the error still occurs.

sentry.client.config.js:

Sentry.init({
  dsn: null,
  // Adjust this value in production, or use tracesSampler for greater control
  tracesSampleRate: 1.0,
  // ...
  // Note: if you want to override the automatic release value, do not set a
  // `release` value here - use the environment variable `SENTRY_RELEASE`, so
  // that it will also get attached to your source maps
});

sentry.client.edge.js:

Sentry.init({
  dsn: null,
  // Adjust this value in production, or use tracesSampler for greater control
  tracesSampleRate: 1.0,
  // ...
  // Note: if you want to override the automatic release value, do not set a
  // `release` value here - use the environment variable `SENTRY_RELEASE`, so
  // that it will also get attached to your source maps
});

sentry.client.server.js:

Sentry.init({
  dsn: null,
  // Adjust this value in production, or use tracesSampler for greater control
  tracesSampleRate: 1.0,
  // ...
  // Note: if you want to override the automatic release value, do not set a
  // `release` value here - use the environment variable `SENTRY_RELEASE`, so
  // that it will also get attached to your source maps
});

Steps to Reproduce

  1. Running on Windows, clone this repository which is a reproduction of the issue
  2. Run yarn install
  3. Run yarn dev
  4. Browse to http://localhost:3000
  5. Observe an error on-screen and in your terminal

Expected Result

Page is rendered successfully.

Actual Result

image

This could be related to #6771? (cc @lforst)

Confirmed that it works as expected with v7.29.0

@josh-
Copy link
Author

josh- commented Jan 19, 2023

Have confirmed that this issue is still present when the middleware.ts and pages directory is in the root folder too (as opposed to the src directory in the reproduction sample app)

@lforst
Copy link
Member

lforst commented Jan 19, 2023

@josh- That looks super fishy. Can you try deleting your .next folder and rebuilding the project or running dev mode agin? Thanks!

@lforst
Copy link
Member

lforst commented Jan 19, 2023

Also just want to make sure you called your config files the following:

  • sentry.client.config.js
  • sentry.edge.config.js
  • sentry.server.config.js

and not

  • sentry.client.config.js
  • sentry.client.edge.js
  • sentry.client.server.js

@josh-
Copy link
Author

josh- commented Jan 19, 2023

@josh- That looks super fishy. Can you try deleting your .next folder and rebuilding the project or running dev mode agin? Thanks!

Yep, same result:

PS C:\Users\Josh\Desktop\windows-next-sentry-middleware-repro> Remove-Item -Path .\.next\ -Recurse
PS C:\Users\Josh\Desktop\windows-next-sentry-middleware-repro> yarn dev
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 2.7s (383 modules)
wait  - compiling /middleware (client and server)...
event - compiled successfully in 1200 ms (344 modules)
wait  - compiling /_error (client and server)...
error - sentry-wrapper-module (31:0) @ <unknown>
error - _sentry_nextjs__WEBPACK_IMPORTED_MODULE_1__.wrapMiddlewareWithSentry is not a function
  29 | 
  30 | const middleware = userProvidedNamedHandler
> 31 |   ? Sentry.wrapMiddlewareWithSentry(userProvidedNamedHandler)
  32 |   : undefined;
  33 | const middlewareWrapperTemplate = userProvidedDefaultHandler ? Sentry.wrapMiddlewareWithSentry(userProvidedDefaultHandler) : undefined;
  34 | 
error - sentry-wrapper-module (31:0) @ <unknown>
error - _sentry_nextjs__WEBPACK_IMPORTED_MODULE_1__.wrapMiddlewareWithSentry is not a function
  29 | 
  30 | const middleware = userProvidedNamedHandler
> 31 |   ? Sentry.wrapMiddlewareWithSentry(userProvidedNamedHandler)
  32 |   : undefined;
  33 | const middlewareWrapperTemplate = userProvidedDefaultHandler ? Sentry.wrapMiddlewareWithSentry(userProvidedDefaultHandler) : undefined;
  34 | 
error - sentry-wrapper-module (31:0) @ <unknown>

We've also been able to reproduce this on several different windows machines who are cloning the issue reproduction repository fresh (and in our internal app where we initially ran into this)

@josh-
Copy link
Author

josh- commented Jan 19, 2023

Also just want to make sure you called your config files the following:

  • sentry.client.config.js
  • sentry.edge.config.js
  • sentry.server.config.js

and not

  • sentry.client.config.js
  • sentry.client.edge.js
  • sentry.client.server.js

Can confirm they are named correctly in the issue reproduction repository (and also our internal app):

PS C:\Users\Josh\Desktop\windows-next-sentry-middleware-repro> Get-ChildItem -Path $path -Filter "*sentry*"


    Directory: C:\Users\Josh\Desktop\windows-next-sentry-middleware-repro


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        19/01/2023   2:14 PM            613 sentry.client.config.js
-a----        19/01/2023   2:14 PM            640 sentry.edge.config.js
-a----        19/01/2023   2:14 PM            621 sentry.server.config.js

@lforst lforst changed the title TypeError when running Next.js app with middleware and latest @sentry/nextjs package [Windows] TypeError when running Next.js app with middleware and latest @sentry/nextjs package Jan 19, 2023
@lforst
Copy link
Member

lforst commented Jan 19, 2023

Ah sorry took me way longer to understand this issue happens on windows than it should have 😬 We'll look into it!

@lforst
Copy link
Member

lforst commented Jan 19, 2023

@josh- Weird ask but can you try replacing line 71 in node_modules/@sentry/nextjs/cjs/config/webpack.js like the following:

- test: /node_modules\/@sentry\/nextjs/,
+ test: /node_modules[\/\\]@sentry[\/\\]nextjs/,

and try building your project again? Thank you!

@memmen
Copy link

memmen commented Jan 19, 2023

@josh- Weird ask but can you try replacing line 71 in node_modules/@sentry/nextjs/cjs/config/webpack.js like the following:

- test: /node_modules\/@sentry\/nextjs/,
+ test: /node_modules[\/\\]@sentry[\/\\]nextjs/,

and try building your project again? Thank you!

I had this error

error - sentry-wrapper-module (33:5) @ <unknown>
error - _sentry_nextjs__WEBPACK_IMPORTED_MODULE_1__.wrapMiddlewareWithSentry is not a function
  31 |   ? Sentry.wrapMiddlewareWithSentry(userProvidedNamedHandler)
  32 |   : undefined;
> 33 | const middlewareWrapperTemplate = userProvidedDefaultHandler ? Sentry.wrapMiddlewareWithSentry(userProvidedDefaultHandler) : undefined;
     |     ^
  34 |
  35 | export { middlewareWrapperTemplate as default, middleware };

This fixed the issue.

@josh-
Copy link
Author

josh- commented Jan 19, 2023

Thanks @lforst 👍 Confirming also this fixes the issue.

@lforst
Copy link
Member

lforst commented Jan 19, 2023

Thanks for confirming @memmen @josh-! We have a fix on its way. It will probably come with a new version on Monday. We avoid releasing on Fridays and Thursdays because we don't like working on the Weekends and all in case there is something going wrong badly.

I recommend downgrading to 7.29.0 until then!

@memmen
Copy link

memmen commented Jan 19, 2023

image

@Geczy
Copy link

Geczy commented Jan 20, 2023

came here for the same issue. i fixed it by disabling middleware instrumentation on dev

  sentry: {
    autoInstrumentMiddleware: !!(
      process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
    ),
    disableServerWebpackPlugin:
      !process.env.SENTRY_DSN && !process.env.NEXT_PUBLIC_SENTRY_DSN,
    disableClientWebpackPlugin:
      !process.env.SENTRY_DSN && !process.env.NEXT_PUBLIC_SENTRY_DSN,

    hideSourceMaps: true,
  },

@lukevella
Copy link

lukevella commented Jan 23, 2023

I'm still seeing this error using 7.32.0 on paths that match my middleware config. I'm using a Mac too so doesn't seem to be specific to Windows.

Here's my repo: https://github.com/lukevella/rallly/tree/update-sentry

@lforst
Copy link
Member

lforst commented Jan 23, 2023

@lukevella Thanks for providing that repo! It helped identifying a regression in the last release. We are in the process of releasing a patch with a fix.

Side-note: Sorry about all these issues with the SDK. We're doing some pretty ambitious stuff to support every feature and it's gotten a little bit fragile. I hope it won't take too long to mature!

@wadehammes
Copy link

wadehammes commented Jan 23, 2023

Will this next patch fix an error I am seeing with latest version (and does this relate to the above)? Getting this with 7.32.0:

Attempted import error: 'wrapMiddlewareWithSentry' is not exported from '@sentry/nextjs' (imported as 'Sentry')

Currently causing Vercel builds to fail. Can open a new issue if this doesn't relate to this.

@lforst
Copy link
Member

lforst commented Jan 23, 2023

Will this next patch fix an error I am seeing with latest version (and does this relate to the above)? Getting this with 7.32.0:

Attempted import error: 'wrapMiddlewareWithSentry' is not exported from '@sentry/nextjs' (imported as 'Sentry')

Currently causing Vercel builds to fail. Can open a new issue if this doesn't relate to this.

@wadehammes Yeah that should be fixed with version 7.32.1. Let me know if upgrading resolves this issue for you.

@lukevella
Copy link

I can confirm that this issue seems to be fixed in 7.32.1. Thanks for the quick turnaround 👍

@lforst
Copy link
Member

lforst commented Jan 23, 2023

I can confirm that this issue seems to be fixed in 7.32.1. Thanks for the quick turnaround 👍

@lukevella Thanks for checking!

@wadehammes
Copy link

@lforst also confirm that the error I was experiencing is fixed in latest

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

Successfully merging a pull request may close this issue.

6 participants