2
2

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 3 years have passed since last update.

Vue3環境を仮想サーバーで構築してnpm run dev を実行した際に3000番ポートにアクセスできない

Last updated at Posted at 2022-04-21

npm run dev でhttp://localhost:3000にアクセスできない

Viteというビルドツールで開発を行うため、必要な環境構築を行いました。
ブラウザで挙動を確認するため、お馴染みの 「npm run dev」 を実行し、ブラウザからhttp://localhost:3000にアクセスしたところ、上手く画面が表示されませんでした。
Viteとは

ターミナルを確認したところ、下記のようになっていました。

console
  vite v2.8.6 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 206ms.

Local環境にアクセスするならば http://localhost:3000/、
Network環境にアクセスするならば 「use --hostして公開(expose)しなさい」 、と書かれています。

したがって、configファイルを修正します。

vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [vue()],
  // ここから追加
  server: {
  host: true
  }
  // ここまで追加
})

再び「npm run dev」を実行します。

console
  vite v2.8.6 dev server running at:

  > Local:    http://localhost:3000/
  > Network:  http://192.xxx.xxx.xxx:3000/ // ここにアクセスする。
  > Network:  http://172.xxx.xxx.xxx:3000/

  ready in 209ms.

Networkが解放されていることが分かります。
再び、ブラウザでアクセスすると、画面が表示されることが分かります。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?