Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'react' #23

Open
Erik-Wong opened this issue Apr 12, 2024 · 5 comments
Open

Cannot find module 'react' #23

Erik-Wong opened this issue Apr 12, 2024 · 5 comments

Comments

@Erik-Wong
Copy link

Uploading WechatIMG530.jpg…

@Haukez
Copy link

Haukez commented Apr 16, 2024

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

@paulkitt
Copy link

Facing the same problem

@itangqiao
Copy link

same problem

image

@itangqiao
Copy link

same problem

image
image

@V-Shadbolt
Copy link

V-Shadbolt commented May 14, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants