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

Next.js 13 app router + @sentry/wizard breaks typing #307

Closed
3 tasks done
trbarton opened this issue Jun 27, 2023 · 3 comments · Fixed by #385
Closed
3 tasks done

Next.js 13 app router + @sentry/wizard breaks typing #307

trbarton opened this issue Jun 27, 2023 · 3 comments · Fixed by #385

Comments

@trbarton
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.56.0

Framework Version

13.4.5

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

This bug appears in a Next 13 app router project using typescript and the App router exclusively.

Create a project and set up a dynamic route in the app directory. e.g. app/post/[id]/page.tsx
On the new page use the useParams() hook from next/navigation to get the id
const { id } = useParams();
This currently will be typed as a string. Running the build command should also be successful

Now run the sentry wizard as per the Sentry next.js setup instructions:
npx @sentry/wizard@latest -i nextjs

Now building will fail due to a type error. This is due to the wizard creating a test route in the pages directory.
We now have both a pages and app directory so next/navigation uses the "compat" types. id is no longer of type string
but instead is of type: Record<string, string, string[]> | null

This caveat should probably be documented in the Next.js setup instructions

Expected Result

An app router project to build successfully after running the sentry wizard

Actual Result

image

@lforst
Copy link
Member

lforst commented Jun 27, 2023

Out of curiosity, will removing the test page fix this error again?

I think we should add a test page to the app dir instead, if the router is used.

@lforst lforst transferred this issue from getsentry/sentry-javascript Jun 27, 2023
@github-actions
Copy link

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

mayank1513 added a commit to mayank1513/sentry-wizard that referenced this issue Jul 29, 2023
- fixes getsentry#307
- checks for appRouter as well
- defaults to creating appRouter if neither page nor app router is detected
@mayank1513
Copy link
Contributor

mayank1513 commented Jul 29, 2023

I have created PR fixing this issue - #385

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

Successfully merging a pull request may close this issue.

4 participants