naskio / docker-strapi

Docker image for strapi v4 (latest version)
https://hub.docker.com/r/naskio/strapi
MIT License
142 stars 49 forks source link

Cannot find module 'react' #23

Open Erik-Wong opened 7 months ago

Erik-Wong commented 7 months ago

![Uploading WechatIMG530.jpg…]()

Haukez commented 7 months ago

repl: load thedocker image with docker pull naskio/strapi then copied docker-compose-yml version: "3" services: strapi: image: naskio/strapi environment: NODE_ENV: development # or production ports:

starting the file with docker compose up -d results in a closed container

Screenshot 2024-04-16 021222

paulkitt commented 6 months ago

Facing the same problem

itangqiao commented 6 months ago

same problem

image
itangqiao commented 6 months ago

same problem

image
image
V-Shadbolt commented 6 months ago

Adding React does not fix the problem in and of itself: react-dom, react-router-dom, and styled-components also will need to be added to the image.

This can be fixed quickly by including the packages in the dockerfile(s) - versions per the error logs

RUN yarn global add @strapi/strapi@${STRAPI_VERSION} && yarn global add "react@^18.0.0" && yarn global add "react-dom@^18.0.0" && yarn global add "react-router-dom@^5.3.4" && yarn global add "styled-components@^5.3.3"

Alternatively, the entire above line in the dockerfile(s) can be dropped as the @strapi/strapi package is what is throwing the dependency errors. Existing projects should start just fine once the line is removed but they will throw a low-level warning for the missing react packages.

For building new Strapi v4 projects with the above removed, migrate the entrypoint(s) from strapi new to yarn create strapi-app@${STRAPI_VERSION} - it is now the recommended way to start a Strapi project per the docs. New projects will be built with the required packages and will use the specified Strapi version.

I just did the migration on my fork for reference. I also included a catch for adding the missing packages to existing projects as well as a version upgrade check to compare the current Strapi project version and the image version; upgrading if necessary.

@naskio I'm happy to open a PR for the migration

kuncevic commented 1 month ago

@V-Shadbolt the fork seems hangs on create app, trying to use >Login/Sign up option

strapi-1  | - ✦ Blazing-fast ✦ deployment for your projects
strapi-1  | - ✦ Exclusive ✦ access to resources to make your project successful
strapi-1  | - An ✦ Awesome ✦ community and full enjoyment of Strapi's ecosystem
strapi-1  | 
strapi-1  | Start your 14-day free trial now!
strapi-1  | 
strapi-1  | 
strapi-1  | ? Please log in or sign up. (Use arrow keys)
strapi-1  | ❯ Login/Sign up 
strapi-1  |   Skip 
strapi-1  | npm notice

I am using default docker compose yaml, starting from the scratch

version: "3"
services:
  strapi:
    image: vshadbolt/strapi:latest
    platform: linux/amd64
    environment:
      NODE_ENV: development # or production
    ports:
      - "1337:1337"
    # volumes:
    #   - ./app:/srv/app # mount an existing strapi project
V-Shadbolt commented 1 month ago

@kuncevic there was a breaking change (in relation to the docker image) between v4 and v5 of Strapi with how the CLI works on project setup. Specifically it prompts user input now for Strapi Cloud login/signup.

Release 4.35.11 of the fork should still work as expected.

There seems to be a flag I can use to bypass the Strapi Cloud questions which should solve the issue but I’ll need to do some testing around it first before I implement it into the docker image.

I would recommend opening this as an issue against my fork for tracking purposes.

jy1989 commented 1 month ago

same problem

V-Shadbolt commented 1 month ago

@jy1989 same problem with my fork or with this one? @kuncevic the issue has been fixed for v4.25.x and v5.x.x. I've also implemented build testing to try avoiding these slipping through moving forward.

AlanStefanov commented 3 weeks ago

I give you two options to move forward:

1: docker run -d -p 1337:1337 naskio/strapi:4.14.5-alpine

2: docker-compose.yml

services: strapi: image: naskio/strapi:4.14.5-alpine restart: always environment:

  DATABASE_CLIENT: postgres
  DATABASE_NAME: strapi
  DATABASE_HOST: x
  DATABASE_PORT: 5432
  DATABASE_USERNAME: postsgres
  DATABASE_PASSWORD: x
  APP_KEYS: x
  JWT_SECRET: x
  ADMIN_JWT_SECRET: x
  SMTP_USER: x
  SMTP_PASS: x

// NODE_ENV: production volumes:

volumes: strapi-data:

nikola66 commented 3 weeks ago

This is still pretty much a problem in all V4 and v5 versions. Just tried it on CapRover and it keeps looping forever with no sucess ![Uploading Screenshot 2024-10-25 145440.png…]()