@@ -18,12 +18,15 @@ import {
1818 abort ,
1919 abortIfCancelled ,
2020 askShouldAddPackageOverride ,
21+ askShouldInstallPackage ,
2122 featureSelectionPrompt ,
23+ installPackage ,
2224 isUsingTypeScript ,
2325} from '../utils/clack-utils' ;
2426import { traceStep } from '../telemetry' ;
2527import { lt , SemVer } from 'semver' ;
26- import { PackageManager } from '../utils/package-manager' ;
28+ import { PackageManager , PNPM } from '../utils/package-manager' ;
29+ import { hasPackageInstalled , PackageDotJson } from '../utils/package-json' ;
2730
2831const possibleNuxtConfig = [
2932 'nuxt.config.js' ,
@@ -212,9 +215,12 @@ export async function createConfigFiles(dsn: string) {
212215}
213216
214217export async function addNuxtOverrides (
218+ packageJson : PackageDotJson ,
215219 packageManager : PackageManager ,
216220 nuxtMinVer : SemVer | null ,
217221) {
222+ const isPNPM = PNPM . detect ( ) ;
223+
218224 const overrides = [
219225 {
220226 pkgName : 'nitropack' ,
@@ -230,9 +236,17 @@ export async function addNuxtOverrides(
230236 ] ;
231237
232238 clack . log . warn (
233- `To ensure Sentry can properly instrument your code it needs to add version overrides for some Nuxt dependencies.\n\nFor more info see: ${ chalk . cyan (
239+ `To ensure Sentry can properly instrument your code it needs to add version overrides for some Nuxt dependencies${
240+ isPNPM ? ` and install ${ chalk . cyan ( 'import-in-the-middle' ) } .` : '.'
241+ } \n\nFor more info see: ${ chalk . cyan (
234242 'https://github.com/getsentry/sentry-javascript/issues/14514' ,
235- ) } `,
243+ ) } ${
244+ isPNPM
245+ ? `\n\nand ${ chalk . cyan (
246+ 'https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle' ,
247+ ) } `
248+ : ''
249+ } `,
236250 ) ;
237251
238252 for ( const { pkgName, pkgVersion } of overrides ) {
@@ -245,4 +259,26 @@ export async function addNuxtOverrides(
245259 await packageManager . addOverride ( pkgName , pkgVersion ) ;
246260 }
247261 }
262+
263+ if ( PNPM . detect ( ) ) {
264+ // For pnpm, we want to install iitm
265+ // See: https://docs.sentry.io/platforms/javascript/guides/nuxt/troubleshooting/#pnpm-dev-cannot-find-package-import-in-the-middle
266+ const iitmAlreadyInstalled = hasPackageInstalled (
267+ 'import-in-the-middle' ,
268+ packageJson ,
269+ ) ;
270+ Sentry . setTag ( 'iitm-already-installed' , iitmAlreadyInstalled ) ;
271+
272+ const shouldInstallIitm = await askShouldInstallPackage (
273+ 'import-in-the-middle' ,
274+ ) ;
275+
276+ if ( shouldInstallIitm ) {
277+ await installPackage ( {
278+ packageName : 'import-in-the-middle' ,
279+ alreadyInstalled : iitmAlreadyInstalled ,
280+ packageManager,
281+ } ) ;
282+ }
283+ }
248284}
0 commit comments