docker-strapi
docker-strapi copied to clipboard
Cannot find module 'react'
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
Facing the same problem
same problem
same problem
![]()
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