Skip to content

Commit

Permalink
fix(nuxt): Add import line for disabled autoImport (#13342)
Browse files Browse the repository at this point in the history
Adds explicit imports in case `autoImport` is disabled (Nuxt docs
[here](https://nuxt.com/docs/guide/concepts/auto-imports#disabling-auto-imports)).
Disabled `autoImport` in the E2E test to verify.

fixes #13302
  • Loading branch information
s1gr1d authored Aug 13, 2024
1 parent 5af8eb8 commit e623782
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dev-packages/e2e-tests/test-applications/nuxt-3/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<nav>
<ul>
<li><NuxtLink to="/fetch-server-error">Fetch Server Error</NuxtLink></li>
<li><NuxtLink to="/param-error/1234">Fetch Param Server Error</NuxtLink></li>
<li><NuxtLink to="/test-param/1234">Fetch Param</NuxtLink></li>
<li><NuxtLink to="/client-error">Client Error</NuxtLink></li>
</ul>
</nav>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: ['@sentry/nuxt/module'],
imports: {
autoImport: false,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
</template>

<script setup lang="ts">
import { useFetch} from '#imports'
const fetchData = async () => {
await useFetch('/api/server-error');
}
</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</template>

<script setup lang="ts">
import { useRoute, useFetch } from '#imports'
const route = useRoute();
const param = route.params.param;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defineEventHandler } from '#imports';

export default defineEventHandler(_e => {
throw new Error('Nuxt 3 Param Server error');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defineEventHandler } from '#imports';

export default defineEventHandler(event => {
throw new Error('Nuxt 3 Server error');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defineEventHandler, getRouterParam } from '#imports';

export default defineEventHandler(event => {
const param = getRouterParam(event, 'param');

Expand Down
2 changes: 2 additions & 0 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default defineNuxtModule<ModuleOptions>({
filename: 'sentry-client-config.mjs',
getContents: () =>
`import "${buildDirResolver.resolve(`/${clientConfigFile}`)}"\n` +
'import { defineNuxtPlugin } from "#imports"\n' +
'export default defineNuxtPlugin(() => {})',
});

Expand All @@ -43,6 +44,7 @@ export default defineNuxtModule<ModuleOptions>({
filename: 'sentry-server-config.mjs',
getContents: () =>
`import "${buildDirResolver.resolve(`/${serverConfigFile}`)}"\n` +
'import { defineNuxtPlugin } from "#imports"\n' +
'export default defineNuxtPlugin(() => {})',
});

Expand Down

0 comments on commit e623782

Please sign in to comment.