First, install magic-regexp:

npm
npm install magic-regexp
yarn
yarn add magic-regexp
pnpm
pnpm install magic-regexp

Second, optionally, you can enable the included transform, which enables zero-runtime usage.

nuxt.config.ts
// Nuxt 3import { defineNuxtConfig } from 'nuxt'export default defineNuxtConfig({  // This will also enable auto-imports of magic-regexp helpers  modules: ['magic-regexp/nuxt'],})
vite.config.ts
import { defineConfig } from 'vite'import { MagicRegExpTransformPlugin } from 'magic-regexp/transform'export default defineConfig({  plugins: [MagicRegExpTransformPlugin.vite()],})
next.config.mjs
// or, if using next.config.js// const { MagicRegExpTransformPlugin } = require('magic-regexp/transform')import { MagicRegExpTransformPlugin } from 'magic-regexp/transform'export default {  webpack(config) {    config.plugins = config.plugins || []    config.plugins.push(MagicRegExpTransformPlugin.webpack())    return config  },}
build.config.ts
// unbuildimport { defineBuildConfig } from 'unbuild'import { MagicRegExpTransformPlugin } from 'magic-regexp/transform'export default defineBuildConfig({  hooks: {    'rollup:options': (options, config) => {      config.plugins.push(MagicRegExpTransformPlugin.rollup())    },  },})