I need to dockerize my react app, but incurring in some troubles:
Compiled with problems:
ERROR in ./node_modules/graphql-tag/lib/index.js 2:0-32
Module not found: Error: Can't resolve 'graphql' in '/app/node_modules/graphql-tag/lib'
ERROR in ./node_modules/@apollo/client/core/LocalState.js 3:0-39
Module not found: Error: Can't resolve 'graphql' in '/app/node_modules/@apollo/client/core'
ERROR in ./node_modules/@apollo/client/link/http/createHttpLink.js 3:0-32
Module not found: Error: Can't resolve 'graphql' in '/app/node_modules/@apollo/client/link/http'
ERROR in ./node_modules/@apollo/client/link/http/selectHttpOptionsAndBody.js 2:0-32
Module not found: Error: Can't resolve 'graphql' in '/app/node_modules/@apollo/client/link/http'
ERROR in ./node_modules/@apollo/client/utilities/globals/fix-graphql.js 2:0-33
Module not found: Error: Can't resolve 'graphql' in '/app/node_modules/@apollo/client/utilities/globals'
ERROR in ./node_modules/@apollo/client/utilities/graphql/directives.js 2:0-32
Module not found: Error: Can't resolve 'graphql' in '/app/node_modules/@apollo/client/utilities/graphql'
ERROR in ./node_modules/@apollo/client/utilities/graphql/transform.js 3:0-32
Module not found: Error: Can't resolve 'graphql' in '/app/node_modules/@apollo/client/utilities/graphql'
here's my dockerfile:
FROM node:13.12.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install
RUN npm install react-scripts@latest -g
run npm build
# add app
COPY . ./
# start app
CMD ["npm", "start"]
here's my docker-compose
version: '3.3'
services:
propoly:
build: .
ports:
- 3002:3002
here's my package.json:
{
"name": "insurance_microfrontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.5.6",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.2"
},
"scripts": {
"start": "PORT=3002 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
CodePudding user response:
graphql
is not listed in your package.json
Run npm i --save graphql
, then rebuild your Docker container.
This should fix the error.
CodePudding user response:
The next time you need to check apollo documentation.
From time to time they are adding new dependencies.
It is not working, because graphql is not installed in your project. You have graphql available globally that's why locally it working fine.