docker-strapi icon indicating copy to clipboard operation
docker-strapi copied to clipboard

Cannot find module 'react'

Open Erik-Wong opened this issue 10 months ago • 16 comments

Uploading WechatIMG530.jpg…

Erik-Wong avatar Apr 12 '24 04:04 Erik-Wong

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: - "1337:1337"

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

Screenshot 2024-04-16 021222

Haukez avatar Apr 16 '24 00:04 Haukez

Facing the same problem

paulkitt avatar Apr 25 '24 18:04 paulkitt

same problem

image

itangqiao avatar May 09 '24 19:05 itangqiao

same problem

image
image

itangqiao avatar May 09 '24 19:05 itangqiao

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

V-Shadbolt avatar May 14 '24 21:05 V-Shadbolt