LoginSignup
1
0

More than 1 year has passed since last update.

[AWS]ReactアプリケーションをS3にデプロイするときにyarn buildができない

Posted at

初めに

今回はReactアプリケーションを初めてS3にデプロイしようとしたときに直面したエラーについて綴っていこうと思います。
かなり初歩的なミスなのですが、自分への戒めとして残していきます。

ディレクトリ構成は以下の通り
(dockerにて環境を作っております。)

front
├ app
┃  ├ node_modules
┃  ├ public
┃  ├ src
┃  ├ types
┃  ├ package.json ・・・①
┃  ├ README.md
┃  ├ tsconfig.json
┃  └  yarn.lock
├ node_modules
├ Dockerfile
├ package.json ・・・②
└ yarn.lock 

frontディレクトリにてyarn buildを実行。

$ cd xxx/front

$ yarn build

すると、下記のエラー発生。

error Command "build" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

yarnにbuildコマンドがないということ、、、
とりあえず、上記ディレクトリのpackage.json②をみてみることに。

package.json②
{
  "dependencies": {
    .
    .
    .
  },
  "devDependencies": {
    .
    .
    .
  }
}


buildが確かにない、、、
ここでpackage.jsonがもうひとつあることに気づき、中身を確認。

package.json①
{
  "name": "app",
    .
    .
    .
  "scripts": {
    "start": "NODE_ENV=production react-scripts start",
    "build": "NODE_ENV=production react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
    .
    .
    .
}

buildがありました。

解決策

もともとfrontディレクトリ内で yarn build を行なっていたのですが、実際に行うべきだったのはappディレクトリ内でした。
dockerで環境を構築している分、通常の環境よりもディレクトリ構成が複雑になっていたので、間違えないように気をつけます。

$ cd /app

$ yarn build

成功しました。

1
0
1

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
0