0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Devcontainerで起動したReact+Viteアプリにlocalhost:5173でアクセスするとERR_SSL_PROTOCOL_ERRORとなる

Posted at

環境

  • React 19.1.0
  • macOS 15.3
  • Vite 6.3
  • devcontainer使用
  • React Router 7.5.3

現象

devcontainerで立ち上げたReactアプリにlocalhost:5173でChromeからアクセスするとERR_SSL_PROTOCOL_ERRORが表示される
image.png

設定ファイル

devcontainerの設定で5173ポートはポートフォワーディングしている

devcontainer.json
{
    ...
    "forwardPorts": [5173],
    ...
}

docker-compose.ymlでも同様

docker-compose.yml
services:
  react:
    # 省略
    ports:
      - 5173:5173

vite.config.jsは以下の通り

vite.config.js
import { reactRouter } from '@react-router/dev/vite';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
    plugins: [reactRouter(), tsconfigPaths()],
});

解決策1

vite.config.jsにhost: true を追記

vite.config.js
import { reactRouter } from '@react-router/dev/vite';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
    server: {
        host: true,
    },
    plugins: [reactRouter(), tsconfigPaths()],
});

http://0.0.0.0:5173 でアクセスできるようになるが localhost:5173 ではアクセスできないため、ライブラリなどで問題が起こった

解決策2

httpsでアクセスできるようにする(@vitejs/plugin-basic-sslをインポートしてpluginとしてvite.config.jsに追加)
これでlocalhost:5173 でアクセスできる

vite.config.js
import { reactRouter } from '@react-router/dev/vite';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import basicSsl from '@vitejs/plugin-basic-ssl';

export default defineConfig({
    server: {
        host: true,
    },
    plugins: [reactRouter(), tsconfigPaths(), basicSsl()],
});

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?