問題
docker-composeをもちいてdjango,postgresql,reactをもちいたwebかいはつをおこなっております。
docker内で、reactをbuildしたさいになぜか、pakage.jsonにあるものをinstallしてくれません。
そのため、react-scriptsがないとerrorでおこられます。
がいとうするファイルを共有します。
該当するコード
docker-compose.yml
version: '3' services: db: image: postgres ports: - "5432:5432" environment: POSTGRES_HOST_AUTH_METHOD: 'trust' django: build: ./backend volumes: - ./backend:/backend ports: - "8000:8000" depends_on: - db command: "bash -c 'python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000'" tty: true frontend: build: ./frontend entrypoint: "bash -c 'npm install && yarn start'" volumes: - ./frontend:/frontend ports: - "3000:3000" depends_on: - django volumes: node-modules:
frontのDockerfile
FROM node WORKDIR /frontend COPY package.json /frontend RUN yarn install COPY . /frontend EXPOSE 3000 CMD ["yarn", "run", "start"]
エラー
db_1 | db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization db_1 | db_1 | 2021-02-04 07:24:11.717 UTC [1] LOG: starting PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit db_1 | 2021-02-04 07:24:11.717 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 db_1 | 2021-02-04 07:24:11.717 UTC [1] LOG: listening on IPv6 address "::", port 5432 db_1 | 2021-02-04 07:24:11.736 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" db_1 | 2021-02-04 07:24:11.745 UTC [29] LOG: database system was interrupted; last known up at 2021-02-04 07:21:58 UTC db_1 | 2021-02-04 07:24:11.831 UTC [29] LOG: database system was not properly shut down; automatic recovery in progress db_1 | 2021-02-04 07:24:11.832 UTC [29] LOG: redo starts at 0/163C2B0 db_1 | 2021-02-04 07:24:11.832 UTC [29] LOG: invalid record length at 0/163C2E8: wanted 24, got 0 db_1 | 2021-02-04 07:24:11.832 UTC [29] LOG: redo done at 0/163C2B0 db_1 | 2021-02-04 07:24:11.840 UTC [1] LOG: database system is ready to accept connections django_1 | No changes detected django_1 | Operations to perform: django_1 | Apply all migrations: admin, auth, contenttypes, sessions, todo django_1 | Running migrations: django_1 | No migrations to apply. django_1 | Performing system checks... django_1 | django_1 | System check identified no issues (0 silenced). django_1 | February 04, 2021 - 07:24:13 django_1 | Django version 3.1.6, using settings 'backend.settings' django_1 | Starting development server at http://0.0.0.0:8000/ django_1 | Quit the server with CONTROL-C. frontend_1 | frontend_1 | changed 10 packages, and audited 1835 packages in 2s frontend_1 | frontend_1 | found 0 vulnerabilities frontend_1 | npm notice frontend_1 | npm notice New patch version of npm available! 7.5.1 -> 7.5.2 frontend_1 | npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.5.2> frontend_1 | npm notice Run `npm install -g npm@7.5.2` to update! frontend_1 | npm notice frontend_1 | yarn run v1.22.5 frontend_1 | $ react-scripts start frontend_1 | /bin/sh: 1: react-scripts: not found frontend_1 | error Command failed with exit code 127. frontend_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. todo_test_frontend_1 exited with code 127
ためしたこと、
Dockerfileにたいして、RUN npm install
をRUN yarn install
に変更。
npm notice npm notice New patch version of npm available! 7.5.1 -> 7.5.2 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.5.2> npm notice Run `npm install -g npm@7.5.2` to update! npm notice npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Found: react@17.0.1 npm ERR! node_modules/react npm ERR! react@"^17.0.1" from the root project npm ERR! peer react@"*" from @testing-library/react@11.2.5 npm ERR! node_modules/@testing-library/react npm ERR! @testing-library/react@"^11.1.0" from the root project npm ERR! 3 more (react-dom, react-scripts, reactstrap) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react@"0.14.x || ^15.0.0 || ^16.0.0" from react-popper@1.3.7 npm ERR! node_modules/reactstrap/node_modules/react-popper npm ERR! react-popper@"^1.3.6" from reactstrap@8.9.0 npm ERR! node_modules/reactstrap npm ERR! reactstrap@"^8.9.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /root/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2021-02-04T08_40_33_006Z-debug.log
node_moudelsをマウントして、package.jsonのreact_scriptsのpathを変更した
frontend_1 | frontend_1 | removed 317 packages, and audited 1835 packages in 3s frontend_1 | frontend_1 | found 0 vulnerabilities frontend_1 | npm notice frontend_1 | npm notice New patch version of npm available! 7.5.1 -> 7.5.2 frontend_1 | npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.5.2> frontend_1 | npm notice Run `npm install -g npm@7.5.2` to update! frontend_1 | npm notice frontend_1 | yarn run v1.22.5 frontend_1 | $ react-scripts start frontend_1 | node:internal/modules/cjs/loader:928 frontend_1 | throw err; frontend_1 | ^ frontend_1 | frontend_1 | Error: Cannot find module 'rollup-plugin-babel' frontend_1 | Require stack: frontend_1 | - /frontend/node_modules/workbox-build/build/lib/bundle.js frontend_1 | - /frontend/node_modules/workbox-webpack-plugin/build/generate-sw.js frontend_1 | - /frontend/node_modules/workbox-webpack-plugin/build/index.js frontend_1 | - /frontend/node_modules/react-scripts/config/webpack.config.js frontend_1 | - /frontend/node_modules/react-scripts/scripts/start.js frontend_1 | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15) frontend_1 | at Function.Module._load (node:internal/modules/cjs/loader:769:27) frontend_1 | at Module.require (node:internal/modules/cjs/loader:997:19) frontend_1 | at require (node:internal/modules/cjs/helpers:92:18) frontend_1 | at Object.<anonymous> (/frontend/node_modules/workbox-build/build/lib/bundle.js:22:15) frontend_1 | at Module._compile (node:internal/modules/cjs/loader:1108:14) frontend_1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10) frontend_1 | at Module.load (node:internal/modules/cjs/loader:973:32) frontend_1 | at Function.Module._load (node:internal/modules/cjs/loader:813:14) frontend_1 | at Module.require (node:internal/modules/cjs/loader:997:19) { frontend_1 | code: 'MODULE_NOT_FOUND', frontend_1 | requireStack: [ frontend_1 | '/frontend/node_modules/workbox-build/build/lib/bundle.js', frontend_1 | '/frontend/node_modules/workbox-webpack-plugin/build/generate-sw.js', frontend_1 | '/frontend/node_modules/workbox-webpack-plugin/build/index.js', frontend_1 | '/frontend/node_modules/react-scripts/config/webpack.config.js', frontend_1 | '/frontend/node_modules/react-scripts/scripts/start.js' frontend_1 | ] frontend_1 | } frontend_1 | error Command failed with exit code 1. frontend_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。