sentry-wizard icon indicating copy to clipboard operation
sentry-wizard copied to clipboard

Next.js .mjs/.ts setup issue

Open TheCukitoDev opened this issue 1 year ago • 6 comments

Core or SDK?

Platform/SDK

Which part? Which one?

Next.js Docs (https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/)

Description

Next.js comes by default with support only for ES6 so the mjs should be the default. Also I think while installing sentry with the wizard should install the ES6 version instead of the cjs version

Suggested Solution

Install the ES6 version instead of the cjs version or add a function that detects what version uses only reading package.json select what version install. Like if it says type: module install the es6 version or in the CLI ask what version should install.

TheCukitoDev avatar Sep 03 '24 14:09 TheCukitoDev

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] avatar Sep 03 '24 14:09 getsantry[bot]

@TheCukitoDev are you referring to the cjs tab being selected by default in the docs?

chargome avatar Sep 06 '24 08:09 chargome

also but the main issue is while executing the wizzard doesen't cares about the project js specification. It always install the CJS version instead of the ES6 that nextjs uses.

TheCukitoDev avatar Sep 07 '24 16:09 TheCukitoDev

@TheCukitoDev you are right, if no previous config was found we create a js file by default as this works with the majority of Next.js versions. We have this on our backlog 👍

chargome avatar Sep 09 '24 08:09 chargome

Next.js 15 has been released with support for typescript configuration files, so you could probably add next.config.ts to this ticket ... EDIT: or should I open a new issue?

chrisweb avatar Oct 29 '24 12:10 chrisweb

@chrisweb nah we can reuse this one!

lforst avatar Oct 29 '24 13:10 lforst

@chrisweb can I ask back on your point? The wizard should already detect your next.config.ts file when setting up. Was this not the case for you?

What this issue is mostly about is when the wizard creates a fresh next.config.* file. We almost certainly cannot default to creating a .ts file because not everybody uses typescript and detecting it is unnecessarily complex.

lforst avatar Oct 30 '24 15:10 lforst

Fixed with https://github.com/getsentry/sentry-wizard/pull/699

lforst avatar Oct 30 '24 16:10 lforst

can I ask back on your point? The wizard should already detect your next.config.ts file when setting up. Was this not the case for you?

@lforst I mean when I reported the problem I had just gotten this output:

◇ Installed @sentry/nextjs with NPM. │ ◆ Created fresh sentry.server.config.ts. │ ◆ Created fresh sentry.client.config.ts. │ ◆ Created fresh sentry.edge.config.ts. │ ◆ Created next.config.js with Sentry configuration. │ ◆ Created app\global-error.jsx. │ ◆ Do you want to create an example page ("/sentry-example-page") to test your Sentry setup? ◇ Do you want to create an example page ("/sentry-example-page") to test your Sentry setup? │ Yes │ ◆ Created app\sentry-example-page\page.jsx. │ ◆ Created app\api\sentry-example-api\route.js.

As you can see Sentry wizard did not create the instrumentation.ts and also created some ts files but mostly added js files

However I'm sorry, I can't reproduce my case anymore

I did two new reproductions, the first one using the latest 3.34.3, and as it worked I thought maybe it was a problem in the previous version, so I also tryied with sentry wizard 3.34.2 but again everything worked as expected and all ts files got created as expected

Anyway, at least this gives me an occasion to thank you for all the updates, I can imagine that it is challenging to keep up with all the Next.js changes ;)

chrisweb avatar Oct 30 '24 18:10 chrisweb