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

fix(nuxt): Add import line for disabled autoImport #13342

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to check: This does not cause problems if auto import is enabled, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this doesn't cause problems. Auto-import just auto-imports if it is not there. If there is an import, it's fine as well. It's always okay to explicitly import. (docs here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, thx for explaining!

'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
Loading