Open5

Nuxt 3(bridge)移行で詰まったポイント

sukezanesukezane

エラー内容:
Module parse failed: Identifier 'defineNuxtPlugin' has already been declared

発生時の状況:
capi: true で発生

nuxt.config.js
export default defineNuxtConfig({
  bridge: {
    capi: true,
    nitro: false
  },
})

対処:

babel: {compact: true} の設定を削除

nuxt.config.js
export default {
  build: {
    babel: {
      compact: true,
    },
  },
};
sukezanesukezane

エラー内容:
Cannot destructure property '__extends' of '_tslib_js__WEBPACK_IMPORTED_MODULE_0___default.a' as it is undefined

https://github.com/nuxt/bridge/issues/228

発生時の状況:
sentryモジュールが導入されている場合に発生(nuxt3非対応のため)

nuxt.config.js
modules: [
  '@nuxtjs/sentry
]

対処法:
pluginにファイル sentry.client.jsを作成する。グローバルで使用する場合、nuxtApp.provideでプラグインを作成する

sentry.client.js
import { defineNuxtPlugin } from '#app'

export default defineNuxtPlugin(async (nuxtApp) => {
  const sentry = await import('@sentry/vue')

  sentry.init({
    dsn: process.env.SENTRY_DSN || false, // DSN
    app: nuxtApp.vueApp
  })
  nuxtApp.provide('sentry', sentry)
})

sukezanesukezane

エラー内容:
Cannot read properties of undefined (reading 'resolve')

発生時の状況:
vee-validateのValidationObserverコンポーネントを使用している際に発生

form.vue
<ValidationObserver v-slot="{ handleSubmit }">
  <!-- 応募フォームなど -->
</ValidationObserver>

対処法:
plugins/vee-validate.jsに defineNuxtPluginを使用していなかったため、使用

sukezanesukezane

エラー内容:
Cannot start nuxt: Cannot read properties of undefined (reading 'hook')

発生時の状況:

  • nitro: true 時に発生

対処法:

  • package-lock.json, node_modulesディレクトリ削除、再インストールで起動が確認できた