1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vueで"Vue app aliases are not allowed in server routes."のエラー

1
Posted at

以下のコードでVue app aliases are not allowed in server routes.のエラーが出る

Vueのアプリでnuxt.config.jsonで設定したsecretを読み取ろうとしたところ、エラーになりました。
app/server/api/hoge.ts

import { useRuntimeConfig } from '#app';

export default defineEventHandler((event) => {
  console.log(runtimeConfig.public.secret);

  return {
    hello: 'hello'
  }
})

修正方法

useRunTimeConfigのインポートの仕方がサーバーサイドだと#importsになるようです。

import { useRuntimeConfig } from '#imports'; // ここを修正

export default defineEventHandler((event) => {
  console.log(runtimeConfig.public.secret);

  return {
    hello: 'hello'
  }
})

正常にログが出力されました。
Nuxt のサーバールートでは #app ではなく #imports を使う必要がありました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?