dockerised react.js app, module not found

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 <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e3c2b2f2d3a633d2d3c273e3a3d0e222f3a2b3d3a">[email protected]</a> -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"
    ]
  }
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

graphql is not listed in your package.json

Run npm i --save graphql, then rebuild your Docker container.

This should fix the error.

Method 2

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x