Fabian B.
Fabian B.
Explore posts from servers
NNuxt
Created by Fabian B. on 8/9/2024 in #❓・help
VSCode Typechecking very slow: Takes up to 20s
Hi there! I noticed that in a larger Nuxt project (using layers with pnpm monorepo packages), the type checking became very slow. I notice this when I for example hover over a config object in nuxt.config.ts. It takes up to 20s to load that type definition. For that time, VSCode displays loading. Same for dependencies in TS files. If I write a function and add a dependency, it takes up to 20s to get the error of missing dependency to go away. It's hard to reproduce because it only appears on larger projects. I noticed that once the type definition is loaded, hovering it then is displaying it instantly. Does anybody have the same issue? And any tips on how to debug intellisense performance, and if it's a Nuxt or Volar issue? Thanks 🙂
2 replies
NNuxt
Created by Fabian B. on 2/29/2024 in #❓・help
Reactive Route Search Query Composable
Does somebody have deeper experience with this? I am trying to implement a composable to reactively use a route search query. Meaning that the value updates reactively whenever the route query parameter changes. And when setting a new value with .value, it does a navigateTo() in the background. However, there are issues with SSR, which makes it hard to implement this. This is how I got so far:
export const useRouteSearchQuery = ({
name = "q",
defaultValue = "",
replace = false,
}: { name?: string; defaultValue?: string; replace?: boolean } = {}) => {
const requestUrl = useRequestURL();
const route = useRoute();

const searchQuery = computed({
get: () => {
console.log("-> getter", {
routeVal: route.query[name],
staticVal: requestUrl.searchParams.get(name),
});

// Reactive, but doesnt work in ssr
const routeVal = route.query[name];
if (routeVal) return String(routeVal);

// Non reactive, works in ssr
const staticVal = requestUrl.searchParams.get(name);
if (staticVal) return String(staticVal);

return defaultValue;
},
set: (newVal: string | undefined) => {
const query = { ...route.query };
if (newVal?.length) {
query[name] = newVal;
} else {
delete query[name];
}

navigateTo({ query }, { replace });
},
});

return { searchQuery };
};
export const useRouteSearchQuery = ({
name = "q",
defaultValue = "",
replace = false,
}: { name?: string; defaultValue?: string; replace?: boolean } = {}) => {
const requestUrl = useRequestURL();
const route = useRoute();

const searchQuery = computed({
get: () => {
console.log("-> getter", {
routeVal: route.query[name],
staticVal: requestUrl.searchParams.get(name),
});

// Reactive, but doesnt work in ssr
const routeVal = route.query[name];
if (routeVal) return String(routeVal);

// Non reactive, works in ssr
const staticVal = requestUrl.searchParams.get(name);
if (staticVal) return String(staticVal);

return defaultValue;
},
set: (newVal: string | undefined) => {
const query = { ...route.query };
if (newVal?.length) {
query[name] = newVal;
} else {
delete query[name];
}

navigateTo({ query }, { replace });
},
});

return { searchQuery };
};
Works in most cases, but in the case where I do a navigateTo() in any component (or the user is navigating back & forth) where certain query parameters are getting removed (e.g. from ?foo=bar&xyz=abc to ?foo=bar), it's still not reactive (watching the searchQuery value reacts to changes in the query parameters, not not when it gets removed e.g. from the user navigating back & forth).
3 replies
DTDrizzle Team
Created by Fabian B. on 2/14/2024 in #help
How do I write a subquery inside select?
I have this SQL which is doing what I want
SELECT
"job_types"."id",
"job_types"."name",
(
SELECT
json_build_array("job_types_parent"."id", "job_types_parent"."name")
FROM
"job_types" "job_types_parent"
WHERE
"job_types_parent"."id" = "job_types"."parent_id"
LIMIT 1
) AS "parent"
FROM
"job_types"
WHERE
"job_types"."parent_id" IS NOT NULL;
SELECT
"job_types"."id",
"job_types"."name",
(
SELECT
json_build_array("job_types_parent"."id", "job_types_parent"."name")
FROM
"job_types" "job_types_parent"
WHERE
"job_types_parent"."id" = "job_types"."parent_id"
LIMIT 1
) AS "parent"
FROM
"job_types"
WHERE
"job_types"."parent_id" IS NOT NULL;
The query selection representation for this would be
const allJobTypesQuery = db.query.jobTypes.findMany({
columns: {
id: true,
name: true,
},
with: {
parent: {
columns: {
id: true,
name: true,
},
},
},
where: (t, { isNotNull }) => isNotNull(t.parentId),
});
const allJobTypesQuery = db.query.jobTypes.findMany({
columns: {
id: true,
name: true,
},
with: {
parent: {
columns: {
id: true,
name: true,
},
},
},
where: (t, { isNotNull }) => isNotNull(t.parentId),
});
which also works. But I need a representation in a normal select query. I am trying to wrap my head around this, but it just does not seem to work. So far I got this, but not sure if I am on the right path here. I don't see how I can select from the subquery in allJobTypesManual.
const jobTypesParent = aliasedTable(jobTypes, "jobTypes_parent");

const sq = db
.select({
data: sql`json_build_array("parent"."id", "parent"."name")`.as('parent_data'),
})
.from(jobTypesParent)
.where(eq(jobTypesParent.id, jobTypes.parentId))
.limit(1)
.as("parent");

const allJobTypesManual = await db
.select({
jobType: {
id: jobTypes.id,
name: jobTypes.name,
},
// how do I select the subquery fields here?
})
.from(jobTypes)
.where(isNotNull(jobTypes.parentId))
.groupBy(jobTypes.id);
const jobTypesParent = aliasedTable(jobTypes, "jobTypes_parent");

const sq = db
.select({
data: sql`json_build_array("parent"."id", "parent"."name")`.as('parent_data'),
})
.from(jobTypesParent)
.where(eq(jobTypesParent.id, jobTypes.parentId))
.limit(1)
.as("parent");

const allJobTypesManual = await db
.select({
jobType: {
id: jobTypes.id,
name: jobTypes.name,
},
// how do I select the subquery fields here?
})
.from(jobTypes)
.where(isNotNull(jobTypes.parentId))
.groupBy(jobTypes.id);
Thanks in advance!
2 replies
NNovu
Created by Fabian B. on 1/25/2024 in #💬│support
Workflows: Dynamically provide custom email template
Hi there! I want to build a workflow where I digest a few events and then send out an email with a list of those. I use Brevo (Sendinblue) to send these emails. I would like to either create the email templates 1. using Brevo (https://developers.brevo.com/docs/send-a-transactional-email#creating-your-api-request-using-brevo-api-clients) 2. or generate them by myself by feeding react-email/vue-email (which renders to html) with the events data and then send this email. Is there currently a way of doing this?
14 replies
DTDrizzle Team
Created by Fabian B. on 1/15/2024 in #help
type "GEOMETRY(POINT)" does not exist
Hi there! I try to use PostGIS with drizzle and having a hard time. I try to run the following migration file
ALTER TABLE "locations" ADD COLUMN "geoPoint" "GEOMETRY(POINT)";
ALTER TABLE "locations" ADD COLUMN "geoPoint" "GEOMETRY(POINT)";
But it errors with
PostgresError: type "GEOMETRY(POINT)" does not exist
at ErrorResponse (file:///Users/fabian/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:790:26)
at handle (file:///Users/fabian/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:476:6)
at Socket.data (file:///Users/fabian/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42704',
position: '47',
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
PostgresError: type "GEOMETRY(POINT)" does not exist
at ErrorResponse (file:///Users/fabian/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:790:26)
at handle (file:///Users/fabian/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:476:6)
at Socket.data (file:///Users/fabian/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42704',
position: '47',
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
Even though PostGIS is setuped successfully. When I run this SQL in supabase directly, it correctly adds the new column with the special data type. I'm not the only one: https://github.com/drizzle-team/drizzle-orm/issues/1315 Maybe someone has an idea, would be grateful!
12 replies
DTDrizzle Team
Created by Fabian B. on 8/27/2023 in #help
on every `migrate()`: schema "drizzle" already exists, skipping
Hi there! I have setuped a postgres DB. Everytime I call migrate(), it works and migrates, but returns these two warnings:
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '128',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '209',
routine: 'transformCreateStmt'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '128',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '209',
routine: 'transformCreateStmt'
}
Does anyone have an idea on why this happens and how I can stop it from happening? Clogs up my console 😄 Thanks! -- I am using [email protected], [email protected], [email protected]
11 replies
NNuxt
Created by Fabian B. on 7/24/2023 in #❓・help
Getting the name of the currently active layout inside a component
I want to get the name of the current active layout in some component. So that I can do things like if (layout === 'xxx') { ... }. Since I am defining it in definePageMeta in the page's component, maybe there is a composable that I can use to retrieve the layout name inside a child component.
1 replies
NNuxt
Created by Fabian B. on 7/12/2023 in #❓・help
Cannot find module `...@nuxt/devtools`
Hi there. I just installed a fresh new project with nuxi init. I wanted to npm i, but it returns the following error:
[9:43:38 AM] ERROR Error while requiring module /Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/@nuxt/devtools/module.cjs: Error: Cannot find module '/Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/@nuxt/devtools/module.cjs'
Require stack:
- /Users/fabian/Desktop/code/urzinger-website/index.js


[9:43:38 AM] ERROR Cannot find module '/Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/@nuxt/devtools/module.cjs'
Require stack:
- /Users/fabian/Desktop/code/urzinger-website/index.js

Require stack:
- index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Function.resolve (node:internal/modules/cjs/helpers:116:19)
at Function._resolve [as resolve] (node_modules/.pnpm/[email protected]/node_modules/jiti/dist/jiti.js:1:250100)
at resolveModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2230:29)
at requireModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2240:24)
at loadNuxtModuleInstance (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2435:90)
at async installModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2408:47)
at async initNuxt (node_modules/.pnpm/[email protected]_@[email protected]/node_modules/nuxt/dist/index.mjs:3231:7)
at async loadNuxt (node_modules/.pnpm/[email protected]_@[email protected]/node_modules/nuxt/dist/index.mjs:3304:5)
at async loadNuxt (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2537:19)
[9:43:38 AM] ERROR Error while requiring module /Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/@nuxt/devtools/module.cjs: Error: Cannot find module '/Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/@nuxt/devtools/module.cjs'
Require stack:
- /Users/fabian/Desktop/code/urzinger-website/index.js


[9:43:38 AM] ERROR Cannot find module '/Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/@nuxt/devtools/module.cjs'
Require stack:
- /Users/fabian/Desktop/code/urzinger-website/index.js

Require stack:
- index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Function.resolve (node:internal/modules/cjs/helpers:116:19)
at Function._resolve [as resolve] (node_modules/.pnpm/[email protected]/node_modules/jiti/dist/jiti.js:1:250100)
at resolveModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2230:29)
at requireModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2240:24)
at loadNuxtModuleInstance (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2435:90)
at async installModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2408:47)
at async initNuxt (node_modules/.pnpm/[email protected]_@[email protected]/node_modules/nuxt/dist/index.mjs:3231:7)
at async loadNuxt (node_modules/.pnpm/[email protected]_@[email protected]/node_modules/nuxt/dist/index.mjs:3304:5)
at async loadNuxt (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit/dist/index.mjs:2537:19)
The problem is, I do not even have installed node 16. I only have node 18.16.1. So why does nuxt require a path with a node version I don't have installed? I used node 16 before, but this was a long time ago. I tried to remove and reinstall nvm, node, pnpm from my system, but that didn't help.
4 replies
DTDrizzle Team
Created by Fabian B. on 5/22/2023 in #help
`where` inside relational queries `with` does not work
Hi there! I'm new to drizzle and tried out the relational queries. I want to do a nested where rule inside a with relation. But doing it is giving me type errors (Object literal may only specify known properties, and where does not exist in type) and it's just ignored by the orm. Maybe someone knows what I am doing wrong and why I don't get the option to do a where. Thanks in advance! My query:
const spaceId = '...'

const found = await db.query.projects.findMany({
with: {
customer: {
columns: {
spaceId: true,
},
where: (customers, { eq }) => eq(customers.spaceId, spaceId),
},
},
}),
const spaceId = '...'

const found = await db.query.projects.findMany({
with: {
customer: {
columns: {
spaceId: true,
},
where: (customers, { eq }) => eq(customers.spaceId, spaceId),
},
},
}),
My schema (simplified):
export const spaces = pgTable('spaces', {
id: uuid('id').primaryKey().defaultRandom(),
companyName: text('company_name').notNull(),
companyTaxNumber: text('company_tax_number').notNull(),
companyTaxIdNumber: text('company_tax_id_number'),
companyTaxUstNumber: text('company_tax_ust_number'),
})

export const spacesRelations = relations(spaces, ({ one, many }) => ({
customers: many(customers),
}))

export const projects = pgTable('projects', {
id: uuid('id').primaryKey().defaultRandom(),
name: text('name').notNull(),
status: projectsStatusEnum('status').notNull(),
customerId: uuid('customer_id').references(() => customers.id, {
onDelete: 'set null',
}),
})

export const projectsRelations = relations(projects, ({ one }) => ({
customer: one(customers, {
fields: [projects.customerId],
references: [customers.id],
}),
}))
export const spaces = pgTable('spaces', {
id: uuid('id').primaryKey().defaultRandom(),
companyName: text('company_name').notNull(),
companyTaxNumber: text('company_tax_number').notNull(),
companyTaxIdNumber: text('company_tax_id_number'),
companyTaxUstNumber: text('company_tax_ust_number'),
})

export const spacesRelations = relations(spaces, ({ one, many }) => ({
customers: many(customers),
}))

export const projects = pgTable('projects', {
id: uuid('id').primaryKey().defaultRandom(),
name: text('name').notNull(),
status: projectsStatusEnum('status').notNull(),
customerId: uuid('customer_id').references(() => customers.id, {
onDelete: 'set null',
}),
})

export const projectsRelations = relations(projects, ({ one }) => ({
customer: one(customers, {
fields: [projects.customerId],
references: [customers.id],
}),
}))
9 replies
NNuxt
Created by Fabian B. on 2/21/2023 in #❓・help
Create local Nuxt modules inside a Nuxt project: Do I need a build step?
Hey there! Question to all that worked with modules, especially local ones: I want to create some modules that will live only locally inside my nuxt project. I have done that by creating a modules/my-module/module.ts and modules/my-module/runtime/plugin.ts like you would get from the module starter template. I am using the module in my main app like:
export default defineNuxtConfig({
modules: ['./modules/my-module/module.ts']
})
export default defineNuxtConfig({
modules: ['./modules/my-module/module.ts']
})
This works so far. My question: Now I want to install some dependencies and also inject some types from this module into my main app. Normally you would have "prepack": "nuxt-module-build", in your package.json which would generate some dist/...mjs files. Is this needed when my module is locally installed directly inside a nuxt app? Or can I get types and dependencies to work without that.
7 replies
NNuxt
Created by Fabian B. on 2/15/2023 in #❓・help
Tips for Common Pitfalls (`$fetch` vs `useFetch`, `public` vs `assets`)
Just a note for all, since these questions comes in here regularly. $fetch vs useFetch From the docs:
useFetch, useLazyFetch, useAsyncData and useLazyAsyncData only work during setup or Lifecycle Hooks https://nuxt.com/docs/getting-started/data-fetching#usefetch
So the use... composables only work inside your vue templates. So whenever you have an issue on this, try to use $fetch , and if it's not available import { $fetch } from 'ofetch' (this module is built into nuxt) public vs assets directory Docs: https://nuxt.com/docs/getting-started/assets You mainly want to use the public directory for your static files like fonts, images, videos, etc. They are being served at your project root and will not be modified by vite/webpack. https://nuxt.com/docs/guide/directory-structure/public The assets is only for files that will be processed by vite/webpack, and therefore also mostly need vite file handlers installed. This could be css files, svgs with nuxt-svgo or other files that are being processed on build. https://nuxt.com/docs/getting-started/assets#assets-directory Example: - you have a few woff2 font files, that can be served as-is. You would put them into public - you have some css files you want to include. You would put them into assets and include them with the nuxt.config css option. - you have some 5mb 4000x3000 jpegs: you can either use nuxt/image (where they can stay in public because they are being minified at runtime, not a build time), or you can use a custom vite plugin which would require them to be in assets .
10 replies
NNuxt
Created by Fabian B. on 2/11/2023 in #❓・help
Vercel Analytics with Nuxt 3
Has anyone successfully tried to activate Vercel Analitics on a deployed Nuxt 3 project? Everytime I do, the build fails. It adds the @nuxtjs/web-vitals package automatically and then does this:
[05:51:01.661] Running build in San Francisco, USA (West) – sfo1
[05:51:01.705] Cloning github.com/madebyfabian/madebyfabian (Branch: main, Commit: 10f8644)
[05:51:02.662] Cloning completed: 952.986ms
[05:51:05.075] Running "vercel build"
[05:51:05.645] Vercel CLI 28.15.3
[05:51:06.876] Injecting Nuxt.js analytics plugin "@nuxtjs/web-vitals" to `/vercel/path0/.nuxtrc`
[05:51:06.879] Adding "@nuxtjs/web-vitals" to `package.json` "dependencies"
[05:51:06.989] Detected `pnpm-lock.yaml` generated by pnpm 7...
[05:51:07.011] Installing dependencies...
[05:51:07.877] Error: Command "pnpm install" exited with 1
[05:51:01.661] Running build in San Francisco, USA (West) – sfo1
[05:51:01.705] Cloning github.com/madebyfabian/madebyfabian (Branch: main, Commit: 10f8644)
[05:51:02.662] Cloning completed: 952.986ms
[05:51:05.075] Running "vercel build"
[05:51:05.645] Vercel CLI 28.15.3
[05:51:06.876] Injecting Nuxt.js analytics plugin "@nuxtjs/web-vitals" to `/vercel/path0/.nuxtrc`
[05:51:06.879] Adding "@nuxtjs/web-vitals" to `package.json` "dependencies"
[05:51:06.989] Detected `pnpm-lock.yaml` generated by pnpm 7...
[05:51:07.011] Installing dependencies...
[05:51:07.877] Error: Command "pnpm install" exited with 1
So I installed this module manually but having the exact same issue.
4 replies
NNuxt
Created by Fabian B. on 1/29/2023 in #❓・help
Add custom files to watch for restarting nuxt (just like `nuxt.config.ts`)
Hi, in my nuxt.config.ts, I am importing some typescript files. When changing the nuxt.config.ts file, or e.g. the .env file of a project, nuxt gets restarted. I want to archive the same, so that when I edit one of the files imported, nuxt should also restart:
import { generateSitemap } from './generateSitemap'
import { cookieConfig } from './cookieConfig'

export default defineNuxtConfig({
// ...
})
import { generateSitemap } from './generateSitemap'
import { cookieConfig } from './cookieConfig'

export default defineNuxtConfig({
// ...
})
so in this case if either generateSitemap.ts or cookieConfig is edited, I want to restart the whole nuxt server.
6 replies
NNuxt
Created by Fabian B. on 1/27/2023 in #❓・help
@vue/server-renderer or vue/server-renderer not found on build
I want to use the @vue/server-renderer package to render a vue template on a server endpoint and send the rendered html code via an email. Normally, this is already included in vue, so just
import { renderToString } from 'vue/server-renderer'
import { renderToString } from 'vue/server-renderer'
works on dev, but not on build. It tells me Cannot find module '/Users/fabian/Desktop/code/nuxt-wordpress-starter/.output/server/node_modules/vue/server-renderer/index.js' I tried manually installing the package, so npm i @vue/server-renderer , and importing it like this:
import { renderToString } from '@vue/server-renderer'
import { renderToString } from '@vue/server-renderer'
but same behaviour, works on dev, not on build. Does somebody know how this could be possible? It seems that nuxt is somehow removing this package in build, even though I am importing it.
3 replies
NNuxt
Created by Fabian B. on 1/27/2023 in #❓・help
Render a vue template completely on a server route (and get the string from it)
Hi there. I am using a backend api route to send an email. I have some JS data that I want to render as a HTML template string, which I can send as the email body. I was thinking to use vue as a templating engine, since the whole nuxt ecosystem is vue. So I tried:
// server/api/sendEmail.ts
import { createSSRApp } from 'vue'
import { renderToString } from 'vue/server-renderer'
import template from './template.vue'

export default defineEventHandler(async event => {
const app = createSSRApp({
data: () => ({ count: 1 }),
template: template,
})

const str = await renderToString(app)

// now send the email with the `str` as html body.

return {
htmlString: str,
}
})
// server/api/sendEmail.ts
import { createSSRApp } from 'vue'
import { renderToString } from 'vue/server-renderer'
import template from './template.vue'

export default defineEventHandler(async event => {
const app = createSSRApp({
data: () => ({ count: 1 }),
template: template,
})

const str = await renderToString(app)

// now send the email with the `str` as html body.

return {
htmlString: str,
}
})
// server/utils/template.vue

<template>
<div class="test" :class="{ 'dynamic': true }">
{{ props.count }}
</div>
</template>

<script setup lang="ts">
const props = defineProps<{ count: number }>()
</script>
// server/utils/template.vue

<template>
<div class="test" :class="{ 'dynamic': true }">
{{ props.count }}
</div>
</template>

<script setup lang="ts">
const props = defineProps<{ count: number }>()
</script>
But this gives me a error:
ERROR RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)


1: <template>
^
2: <div class="test" :class="{ 'dynamic': true }">
3: {{ props.count }}
ERROR RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)


1: <template>
^
2: <div class="test" :class="{ 'dynamic': true }">
3: {{ props.count }}
Do you have any idea on how to archive this?
6 replies
NNuxt
Created by Fabian B. on 1/21/2023 in #❓・help
Nuxt/kit: when creating a module, how can I inject a script into the body
Hi there. I am currently creating a nuxt module. One of the things I need to do is, I have a minified .js file I want to inject into the body. But only on client side. I tried
// src/module.ts:
// setup method:

addTemplate({
filename: 'my-script.js',
getContents: () => import(resolve(runtimeDir, 'my-script')),
})

nuxt.options.app.head.script?.push({
src: '/my-script.js',
body: true,
defer: true,
})

// src/runtime/my-script.js
console.log('hello world')
// src/module.ts:
// setup method:

addTemplate({
filename: 'my-script.js',
getContents: () => import(resolve(runtimeDir, 'my-script')),
})

nuxt.options.app.head.script?.push({
src: '/my-script.js',
body: true,
defer: true,
})

// src/runtime/my-script.js
console.log('hello world')
This does include the script directly, so also in SSR. When adding something like if (typeof window !== 'undefined') to only inject it on the client-side, it never gets injected since the src/module.ts seems to only run once on start. I am sure that addTemplate is not the right method. Do you know any method to add a file into the public folder?
21 replies
NNuxt
Created by Fabian B. on 11/27/2022 in #❓・help
Server API endpoints are slow
No description
11 replies