Skip to content

Commit 121ae07

Browse files
authored
feat(nuxt): Add option autoInjectServerSentry (no default import()) (#14553)
As injecting the dynamic `import()` came with a bunch of challenges related to how the build output looks like, this default is changed to make users use the `--import` CLI flag. This PR basically reverts this: #13958
1 parent 3778482 commit 121ae07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1303
-62
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@
1010

1111
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
1212

13+
### Important Changes
14+
15+
- **feat(nuxt): Add option autoInjectServerSentry (no default import()) ([#14553](https://github.com/getsentry/sentry-javascript/pull/14553))**
16+
17+
Using the dynamic `import()` as the default behavior for initializing the SDK on the server-side did not work for every project.
18+
The default behavior of the SDK has been changed, and you now need to **use the `--import` flag to initialize Sentry on the server-side** to leverage full functionality.
19+
20+
Example with `--import`:
21+
22+
```bash
23+
node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs
24+
```
25+
26+
In case you are not able to use the `--import` flag, you can enable auto-injecting Sentry in the `nuxt.config.ts` (comes with limitations):
27+
28+
```json
29+
sentry: {
30+
autoInjectServerSentry: 'top-level-import', // or 'experimental_dynamic-import'
31+
},
32+
```
33+
1334
Work in this release was contributed by @lsmurray. Thank you for your contribution!
1435

1536
## 8.42.0
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Nuxt dev/build outputs
2+
.output
3+
.data
4+
.nuxt
5+
.nitro
6+
.cache
7+
dist
8+
9+
# Node dependencies
10+
node_modules
11+
12+
# Logs
13+
logs
14+
*.log
15+
16+
# Misc
17+
.DS_Store
18+
.fleet
19+
.idea
20+
21+
# Local env files
22+
.env
23+
.env.*
24+
!.env.example
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<NuxtLayout>
3+
<header>
4+
<nav>
5+
<ul>
6+
<li><NuxtLink to="/fetch-server-error">Fetch Server Error</NuxtLink></li>
7+
<li><NuxtLink to="/test-param/1234">Fetch Param</NuxtLink></li>
8+
<li><NuxtLink to="/client-error">Client Error</NuxtLink></li>
9+
</ul>
10+
</nav>
11+
</header>
12+
<NuxtPage />
13+
</NuxtLayout>
14+
</template>
15+
16+
<script setup>
17+
</script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script setup>
2+
import { defineProps } from 'vue';
3+
4+
const props = defineProps({
5+
errorText: {
6+
type: String,
7+
required: true
8+
},
9+
id: {
10+
type: String,
11+
required: true
12+
}
13+
})
14+
15+
const triggerError = () => {
16+
throw new Error(props.errorText);
17+
};
18+
</script>
19+
20+
<template>
21+
<button :id="props.id" @click="triggerError">Trigger Error</button>
22+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This script copies the `import-in-the-middle` content of the E2E test project root `node_modules` to the build output `node_modules`
2+
# For some reason, some files are missing in the output (like `hook.mjs`) and this is not reproducible in external, standalone projects.
3+
#
4+
# Things we tried (that did not fix the problem):
5+
# - Adding a resolution for `@vercel/nft` v0.27.0 (this worked in the standalone project)
6+
# - Also adding `@vercel/nft` v0.27.0 to pnpm `peerDependencyRules`
7+
cp -r node_modules/.pnpm/import-in-the-middle@1.*/node_modules/import-in-the-middle .output/server/node_modules/import-in-the-middle
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
modules: ['@sentry/nuxt/module'],
4+
imports: {
5+
autoImport: false,
6+
},
7+
runtimeConfig: {
8+
public: {
9+
sentry: {
10+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
11+
},
12+
},
13+
},
14+
nitro: {
15+
rollupConfig: {
16+
// @sentry/... is set external to prevent bundling all of Sentry into the `runtime.mjs` file in the build output
17+
external: [/@sentry\/.*/],
18+
},
19+
},
20+
sentry: {
21+
autoInjectServerSentry: 'experimental_dynamic-import',
22+
},
23+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "nuxt-3-dynamic-import",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "nuxt build && bash ./copyIITM.bash",
7+
"dev": "nuxt dev",
8+
"generate": "nuxt generate",
9+
"preview": "nuxt preview",
10+
"start": "node .output/server/index.mjs",
11+
"clean": "npx nuxi cleanup",
12+
"test": "playwright test",
13+
"test:build": "pnpm install && npx playwright install && pnpm build",
14+
"test:assert": "pnpm test"
15+
},
16+
"dependencies": {
17+
"@sentry/nuxt": "latest || *",
18+
"nuxt": "^3.14.0"
19+
},
20+
"devDependencies": {
21+
"@nuxt/test-utils": "^3.14.1",
22+
"@playwright/test": "^1.44.1",
23+
"@sentry-internal/test-utils": "link:../../../test-utils"
24+
},
25+
"overrides": {
26+
"nitropack": "~2.9.7",
27+
"ofetch": "^1.4.0"
28+
}
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup>
2+
import ErrorButton from '../components/ErrorButton.vue';
3+
</script>
4+
5+
<template>
6+
<ErrorButton id="errorBtn" error-text="Error thrown from Nuxt-3 E2E test app"/>
7+
<ErrorButton id="errorBtn2" error-text="Another Error thrown from Nuxt-3 E2E test app"/>
8+
</template>
9+
10+
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
<button @click="fetchData">Fetch Server Data</button>
4+
</div>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import { useFetch} from '#imports'
9+
10+
const fetchData = async () => {
11+
await useFetch('/api/server-error');
12+
}
13+
</script>

0 commit comments

Comments
 (0)