3
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?

@lazarv/react-serverの環境構築方法について (You can remove the following packages from your project: react@19.0.0 expected: react)

Posted at

はじめに

の環境構築をするときに環境構築の方法を間違えていたのでまとめます

問題

ViteでReactの環境構築をしてから@lazarv/react-serverをインストールすると以下のエラーが出ます

> react-server

You don't need to install react, react-dom or react-server-dom-webpack in your project.
@lazarv/react-server already includes a specific version of react, react-dom and react-server-dom-webpack that is compatible with the current version of @lazarv/react-server.
You can remove the following packages from your project:
  react@19.0.0 expected: react@0.0.0-experimental-de1eaa26-20250124 

以前別の方法で回避していたのですが、うまくいかないケースがありました

環境構築方法

@lazarv/react-serverは他のフレームワークとはすこし変わった方法で環境構築ができます。

まずはViteでTypeScriptの環境構築をします

$ npm create vite
✔ Project name: … react-server-handson
✔ Select a framework: › Vanilla
? Select a variant: › - Use arrow-keys. Return to submit.
❯   TypeScript

$ cd react-server-handson
$ npm i @lazarv/react-server

こうすることで@lazarv/react-serverにはReactも同梱されているためサーバーが立ち上げられます。

$ touch react-server.config.mjs
react-server.config.mjs
export default {
  root: "src/app",
};
$ mkdir src/app
$ touch src/app/page.tsx
src/app/page.tsx
export default function Home() {
  return <div>Home</div>;
}

またVSCodeでjsxについて怒られるのでtsconfig.jsonを直します

image.png

tsconfig.json
{
  "compilerOptions": {
    "jsx": "react-jsx", // 追加
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmit": true,

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "noUncheckedSideEffectImports": true
  },
  "include": ["src"]
}
$ npm run dev

http://localhost:3000を開くと無事ページが表示されました

image.png

おわりに

今後もreact-serverをたんきゅうしてきます

3
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
3
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?