backstage / backstage

Backstage is an open framework for building developer portals
https://backstage.io/
Apache License 2.0
27.59k stars 5.85k forks source link

πŸ› Bug Report: Docker image build giving error after updating backstage to 1.20.2 from 1.17.5(Cannot read properties of undefined (reading 'getOption')") #21381

Closed prasoon-pxc closed 7 months ago

prasoon-pxc commented 10 months ago

πŸ“œ Description

I have updated backstage to version 1.20.2, now while building dockerfile, getting below error:

On running below cmd:

RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000     yarn install --frozen-lockfile --production --network-timeout 600000 --ignore-engines

Error:

#23 24.25 error An unexpected error occurred: "/app/node_modules/core-js: Cannot read properties of undefined (reading 'getOption')".
#23 24.25 info If you think this is a bug, please open a bug report with the information provided in "/home/node/.config/yarn/global/yarn-error.log".
#23 24.25 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
#23 24.26 warning Error running install script for optional dependency: "/app/node_modules/cpu-features: Command failed.
#23 24.26 Exit code: 127
#23 24.26 Command: node buildcheck.js > buildcheck.gypi && node-gyp rebuild
#23 24.26 Arguments: 
#23 24.26 Directory: /app/node_modules/cpu-features
#23 24.26 Output:
#23 24.26 /bin/sh: 1: node-gyp: not found"
#23 24.26 info This module is OPTIONAL, you can safely ignore this error
#23 24.59 [1/4] Resolving packages...
#23 25.00 [2/4] Fetching packages...
#23 25.38 [3/4] Linking dependencies...
#23 25.73 [4/4] Building fresh packages...
#23 25.74 success Installed "node-gyp@10.0.1" with binaries:
#23 25.74       - node-gyp
#23 ERROR: process "/bin/sh -c yarn install --frozen-lockfile --production --network-timeout 600000 --ignore-engines" did not complete successfully: exit code: 1
------
 > [stage-2 6/9] RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000     yarn install --frozen-lockfile --production --network-timeout 600000 --ignore-engines:

πŸ‘ Expected behavior

Dockerfile should build successfully

πŸ‘Ž Actual Behavior with Screenshots

Error:

#23 24.25 error An unexpected error occurred: "/app/node_modules/core-js: Cannot read properties of undefined (reading 'getOption')".
#23 24.25 info If you think this is a bug, please open a bug report with the information provided in "/home/node/.config/yarn/global/yarn-error.log".
#23 24.25 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
#23 24.26 warning Error running install script for optional dependency: "/app/node_modules/cpu-features: Command failed.
#23 24.26 Exit code: 127
#23 24.26 Command: node buildcheck.js > buildcheck.gypi && node-gyp rebuild
#23 24.26 Arguments: 
#23 24.26 Directory: /app/node_modules/cpu-features
#23 24.26 Output:
#23 24.26 /bin/sh: 1: node-gyp: not found"
#23 24.26 info This module is OPTIONAL, you can safely ignore this error
#23 24.59 [1/4] Resolving packages...
#23 25.00 [2/4] Fetching packages...
#23 25.38 [3/4] Linking dependencies...
#23 25.73 [4/4] Building fresh packages...
#23 25.74 success Installed "node-gyp@10.0.1" with binaries:
#23 25.74       - node-gyp
#23 ERROR: process "/bin/sh -c yarn install --frozen-lockfile --production --network-timeout 600000 --ignore-engines" did not complete successfully: exit code: 1
------
 > [stage-2 6/9] RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000     yarn install --frozen-lockfile --production --network-timeout 600000 --ignore-engines:

Dockerfile:

FROM node:18-bullseye AS packages

WORKDIR /app
COPY package.json yarn.lock ./ 
COPY packages packages

#COPY plugins plugins

RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -exec rm -rf {} \+

# Stage 2 - Install dependencies and build packages

FROM node:18-bullseye AS build

USER node
WORKDIR /app

COPY --from=packages --chown=node:node /app .

# Stop cypress from downloading it's massive binary
ENV CYPRESS_INSTALL_BINARY=0
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
    yarn install --frozen-lockfile --network-timeout 600000 --ignore-engines

#RUN mkdir -p /home/node/.cache1/yarn && chown -R node:node /home/node/.cache1/yarn
#RUN yarn config set cache-folder /home/node/.cache1/yarn    

COPY --chown=node:node . .

RUN yarn tsc

RUN yarn --cwd packages/backend build

# If you have not yet migrated to package roles, use the following command instead:
#RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies

RUN mkdir packages/backend/dist/skeleton packages/backend/dist/bundle \
    && tar xzf packages/backend/dist/skeleton.tar.gz -C packages/backend/dist/skeleton \
    && tar xzf packages/backend/dist/bundle.tar.gz -C packages/backend/dist/bundle

# Stage 3 - Build the actual backend image and install production dependencies
FROM node:18-bullseye

RUN apt-get update && apt-get install -y python3 python3-pip git cmake g++ 

#RUN rm -rf /var/lib/apt/lists/*
#RUN yarn config set python /usr/bin/python3 # To set python env

RUN pip3 install mkdocs-techdocs-core==1.*

#RUN apt-get install -y gcc musl-dev openjdk17-jdk curl graphviz ttf-dejavu fontconfig
#RUN curl -o plantuml.jar -L http://sourceforge.net/projects/plantuml/files/plantuml.1.2022.4.jar/download && echo "246d1ed561ebbcac14b2798b45712a9d018024c0  plantuml.jar" | sha1sum -c - && mv plantuml.jar /opt/plantuml.jar

USER node
WORKDIR /app

COPY --from=build --chown=node:node /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton/ ./

RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
    yarn install --frozen-lockfile --production --network-timeout 600000 --ignore-engines

# Copy the built packages from the build stage
COPY --from=build --chown=node:node /app/packages/backend/dist/bundle/ ./

# Copy any other files that we need at runtime

COPY --chown=node:node user_mgmt user_mgmt
COPY --chown=node:node app-config.yaml ./

##Config for Plantuml based docs
#RUN echo $'#!/bin/sh\n\njava -jar '/opt/plantuml.jar' ${@}' >> /usr/local/bin/plantuml
#RUN chmod 755 /usr/local/bin/plantuml

#This is enable for software templating to work
#RUN pip3 install cookiecutter

ENV NODE_ENV production

CMD ["node", "packages/backend", "--config", "app-config.yaml"]

Note: I am building dockefile with github actions i.e not using my local system to build image

πŸ‘Ÿ Reproduction steps

Use above dockerfile to build docker image with backstage version 1.20.2

πŸ“ƒ Provide the context for the Bug.

No response

πŸ–₯️ Your Environment

OS:   Linux 5.15.0-88-generic - linux/x64
node: v16.14.0
yarn: 1.22.19
cli:  0.24.0 (installed)
backstage:  1.20.2

Dependencies:
  @backstage/app-defaults                                          1.4.5
  @backstage/backend-app-api                                       0.4.4, 0.5.8
  @backstage/backend-common                                        0.18.5, 0.19.9
  @backstage/backend-dev-utils                                     0.1.2
  @backstage/backend-openapi-utils                                 0.1.0
  @backstage/backend-plugin-api                                    0.5.3, 0.6.7
  @backstage/backend-tasks                                         0.5.12
  @backstage/catalog-client                                        1.4.6
  @backstage/catalog-model                                         1.4.3
  @backstage/cli-common                                            0.1.13
  @backstage/cli-node                                              0.2.0
  @backstage/cli                                                   0.24.0
  @backstage/config-loader                                         1.5.3
  @backstage/config                                                1.1.1
  @backstage/core-app-api                                          1.11.1
  @backstage/core-components                                       0.12.5, 0.13.8
  @backstage/core-plugin-api                                       1.8.0
  @backstage/errors                                                1.2.3
  @backstage/eslint-plugin                                         0.1.3
  @backstage/frontend-plugin-api                                   0.3.0
  @backstage/integration-aws-node                                  0.1.8
  @backstage/integration-react                                     1.1.21
  @backstage/integration                                           1.7.2
  @backstage/plugin-api-docs                                       0.10.0
  @backstage/plugin-app-backend                                    0.3.55
  @backstage/plugin-app-node                                       0.1.7
  @backstage/plugin-auth-backend-module-gcp-iap-provider           0.2.1
  @backstage/plugin-auth-backend-module-github-provider            0.1.4
  @backstage/plugin-auth-backend-module-gitlab-provider            0.1.4
  @backstage/plugin-auth-backend-module-google-provider            0.1.4
  @backstage/plugin-auth-backend-module-oauth2-provider            0.1.4
  @backstage/plugin-auth-backend                                   0.20.0
  @backstage/plugin-auth-node                                      0.2.19, 0.4.1
  @backstage/plugin-bazaar-backend                                 0.3.5
  @backstage/plugin-bazaar                                         0.2.18
  @backstage/plugin-catalog-backend-module-github                  0.4.5
  @backstage/plugin-catalog-backend-module-scaffolder-entity-model 0.1.4
  @backstage/plugin-catalog-backend                                1.15.0
  @backstage/plugin-catalog-common                                 1.0.18
  @backstage/plugin-catalog-graph                                  0.3.0
  @backstage/plugin-catalog-import                                 0.10.2
  @backstage/plugin-catalog-node                                   1.5.0
  @backstage/plugin-catalog-react                                  1.9.0
  @backstage/plugin-catalog                                        1.15.0
  @backstage/plugin-events-node                                    0.2.16
  @backstage/plugin-github-actions                                 0.6.7
  @backstage/plugin-home-react                                     0.1.5
  @backstage/plugin-org                                            0.6.16
  @backstage/plugin-permission-common                              0.7.10
  @backstage/plugin-permission-node                                0.7.18
  @backstage/plugin-permission-react                               0.4.17
  @backstage/plugin-playlist-backend                               0.3.11
  @backstage/plugin-playlist-common                                0.1.12
  @backstage/plugin-playlist                                       0.2.0
  @backstage/plugin-proxy-backend                                  0.4.5
  @backstage/plugin-scaffolder-backend                             1.19.1
  @backstage/plugin-scaffolder-common                              1.4.3
  @backstage/plugin-scaffolder-node                                0.2.8
  @backstage/plugin-scaffolder-react                               1.6.0
  @backstage/plugin-scaffolder                                     1.16.0
  @backstage/plugin-search-backend-module-catalog                  0.1.11
  @backstage/plugin-search-backend-module-pg                       0.5.16
  @backstage/plugin-search-backend-module-techdocs                 0.1.11
  @backstage/plugin-search-backend-node                            1.2.11
  @backstage/plugin-search-backend                                 1.4.7
  @backstage/plugin-search-common                                  1.2.8
  @backstage/plugin-search-react                                   1.7.3
  @backstage/plugin-search                                         1.4.2
  @backstage/plugin-shortcuts                                      0.3.16
  @backstage/plugin-sonarqube-backend                              0.2.9
  @backstage/plugin-sonarqube-react                                0.1.10
  @backstage/plugin-sonarqube                                      0.7.8
  @backstage/plugin-tech-radar                                     0.6.10
  @backstage/plugin-techdocs-backend                               1.9.0
  @backstage/plugin-techdocs-module-addons-contrib                 1.1.2
  @backstage/plugin-techdocs-node                                  1.10.0
  @backstage/plugin-techdocs-react                                 1.1.13
  @backstage/plugin-techdocs                                       1.9.0
  @backstage/plugin-todo-backend                                   0.3.5
  @backstage/plugin-todo                                           0.2.30
  @backstage/plugin-user-settings                                  0.7.12
  @backstage/release-manifests                                     0.0.11
  @backstage/test-utils                                            1.4.5
  @backstage/theme                                                 0.2.19, 0.3.0, 0.4.4
  @backstage/types                                                 1.1.1
  @backstage/version-bridge                                        1.0.7
Done in 0.71s.

πŸ‘€ Have you spent some time to check if this bug has been raised before?

🏒 Have you read the Code of Conduct?

Are you willing to submit PR?

None

awanlin commented 10 months ago

Hi @prasoon-pxc, I'm taking a look at this now, there have been several changes over the versions you upgraded to. The changes that I recommend you make to start are:

I'm sure there are things I've missed so I also recommend taking a look at the upgrade helper: https://backstage.github.io/upgrade-helper/?from=1.17.5&to=1.20.2

As well as the various release notes:

prasoon-pxc commented 10 months ago

Hi @awanlin , thanks for reply, in my view, node-gyp related error is not the one who is preventing from building dockerfile because earlier also it was there and I was able to build and ran successfully, what I thought is preventing from building is below error

#23 24.25 error An unexpected error occurred: "/app/node_modules/core-js: Cannot read properties of undefined (reading 'getOption')".

Meanwhile, I am trying to update from 1.17.5 to 1.18.0 and then to 1.19.0 and onwards, that would help me focus more on one version at a time.

I will get back to you once I have something.

awanlin commented 10 months ago

Ah, yes, you are correct @prasoon-pxc there is an error before the node-gyp error. Most of the recent Issues have be related to node-gyp so I focused on that. If you are having more issues let me know and I'll try and help as best I can πŸ‘

prasoon-pxc commented 10 months ago

@awanlin , here I am again with same error, what I have done differently this time is to update backstage version from 1.17.5 to 1.18.0 and it was completed successfully, I have to manually update typescript version to 5.2.0 in package.json also change below file:

packages/backend/src/index.ts

-const taskScheduler = TaskScheduler.fromConfig(config);
+ const taskScheduler = TaskScheduler.fromConfig(config, { databaseManager });

Now, I am trying to do update from 1.18.0 to 1.19.0:

Manually update below things:

Strange thing is that, my github actions build dockefile successfully first time but after that when I am trying to build it again without doing any changes it started giving error:

27.87 error An unexpected error occurred: "/app/node_modules/core-js: Cannot read properties of undefined (reading 'config')".

Dockerfile:

FROM node:18-bookworm AS packages

WORKDIR /app
COPY package.json yarn.lock ./ 
COPY packages packages

#COPY plugins plugins

RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -exec rm -rf {} \+

# Stage 2 - Install dependencies and build packages

FROM node:18-bookworm AS build

USER node
WORKDIR /app

COPY --from=packages --chown=node:node /app .

# Stop cypress from downloading it's massive binary
ENV CYPRESS_INSTALL_BINARY=0

ENV LEGACY_BACKEND_START=1

RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
    yarn install  --network-timeout 600000 

COPY --chown=node:node . .

RUN yarn tsc

RUN yarn --cwd packages/backend build

RUN mkdir packages/backend/dist/skeleton packages/backend/dist/bundle \
    && tar xzf packages/backend/dist/skeleton.tar.gz -C packages/backend/dist/skeleton \
    && tar xzf packages/backend/dist/bundle.tar.gz -C packages/backend/dist/bundle

# Stage 3 - Build the actual backend image and install production dependencies
FROM node:18-bookworm

RUN apt-get update && apt-get install -y python3 python3-pip git cmake g++ build-essential 

USER node
WORKDIR /app
ENV LEGACY_BACKEND_START=1

COPY --from=build --chown=node:node /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton/ ./

RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
    yarn install  --production --network-timeout 600000 

# Copy the built packages from the build stage
COPY --from=build --chown=node:node /app/packages/backend/dist/bundle/ ./

# Copy any other files that we need at runtime

COPY --chown=node:node user_mgmt user_mgmt
COPY --chown=node:node app-config.yaml ./

ENV NODE_ENV production
ENV LEGACY_BACKEND_START=1

CMD ["node", "packages/backend", "--config", "app-config.yaml"]

backstage-cli-info:

yarn run v1.22.19
$ /home/il58d0/smb/backstage-conf-repo/backstage-conf-repo-original/node_modules/.bin/backstage-cli info
OS:   Linux 5.15.0-88-generic - linux/x64
node: v16.14.0
yarn: 1.22.19
cli:  0.23.1 (installed)
backstage:  1.19.0

Dependencies:
  @backstage/app-defaults                                          1.4.5
  @backstage/backend-app-api                                       0.4.4, 0.5.8
  @backstage/backend-common                                        0.18.5, 0.19.9
  @backstage/backend-dev-utils                                     0.1.2
  @backstage/backend-openapi-utils                                 0.1.0
  @backstage/backend-plugin-api                                    0.5.3, 0.6.7
  @backstage/backend-tasks                                         0.5.12
  @backstage/catalog-client                                        1.4.6
  @backstage/catalog-model                                         1.4.3
  @backstage/cli-common                                            0.1.13
  @backstage/cli-node                                              0.1.5, 0.2.0
  @backstage/cli                                                   0.23.1
  @backstage/config-loader                                         1.5.3
  @backstage/config                                                1.1.1
  @backstage/core-app-api                                          1.11.1
  @backstage/core-components                                       0.12.5, 0.13.8
  @backstage/core-plugin-api                                       1.8.0
  @backstage/errors                                                1.2.3
  @backstage/eslint-plugin                                         0.1.3
  @backstage/frontend-plugin-api                                   0.3.0
  @backstage/integration-aws-node                                  0.1.8
  @backstage/integration-react                                     1.1.21
  @backstage/integration                                           1.7.2
  @backstage/plugin-api-docs                                       0.9.12
  @backstage/plugin-app-backend                                    0.3.55
  @backstage/plugin-app-node                                       0.1.7
  @backstage/plugin-auth-backend-module-gcp-iap-provider           0.2.1
  @backstage/plugin-auth-backend-module-github-provider            0.1.4
  @backstage/plugin-auth-backend-module-gitlab-provider            0.1.4
  @backstage/plugin-auth-backend-module-google-provider            0.1.4
  @backstage/plugin-auth-backend-module-oauth2-provider            0.1.4
  @backstage/plugin-auth-backend                                   0.19.4
  @backstage/plugin-auth-node                                      0.2.19, 0.4.1
  @backstage/plugin-bazaar-backend                                 0.3.5
  @backstage/plugin-bazaar                                         0.2.18
  @backstage/plugin-catalog-backend-module-github                  0.4.5
  @backstage/plugin-catalog-backend-module-scaffolder-entity-model 0.1.4
  @backstage/plugin-catalog-backend                                1.15.0
  @backstage/plugin-catalog-common                                 1.0.18
  @backstage/plugin-catalog-graph                                  0.2.37
  @backstage/plugin-catalog-import                                 0.10.2
  @backstage/plugin-catalog-node                                   1.5.0
  @backstage/plugin-catalog-react                                  1.9.0
  @backstage/plugin-catalog                                        1.15.0
  @backstage/plugin-events-node                                    0.2.16
  @backstage/plugin-github-actions                                 0.6.7
  @backstage/plugin-home-react                                     0.1.5
  @backstage/plugin-org                                            0.6.16
  @backstage/plugin-permission-common                              0.7.10
  @backstage/plugin-permission-node                                0.7.18
  @backstage/plugin-permission-react                               0.4.17
  @backstage/plugin-playlist-backend                               0.3.11
  @backstage/plugin-playlist-common                                0.1.12
  @backstage/plugin-playlist                                       0.1.17
  @backstage/plugin-proxy-backend                                  0.4.5
  @backstage/plugin-scaffolder-backend                             1.19.1
  @backstage/plugin-scaffolder-common                              1.4.3
  @backstage/plugin-scaffolder-node                                0.2.8
  @backstage/plugin-scaffolder-react                               1.6.0
  @backstage/plugin-scaffolder                                     1.16.0
  @backstage/plugin-search-backend-module-catalog                  0.1.11
  @backstage/plugin-search-backend-module-pg                       0.5.16
  @backstage/plugin-search-backend-module-techdocs                 0.1.11
  @backstage/plugin-search-backend-node                            1.2.11
  @backstage/plugin-search-backend                                 1.4.7
  @backstage/plugin-search-common                                  1.2.8
  @backstage/plugin-search-react                                   1.7.3
  @backstage/plugin-search                                         1.4.2
  @backstage/plugin-shortcuts                                      0.3.16
  @backstage/plugin-sonarqube-backend                              0.2.9
  @backstage/plugin-sonarqube-react                                0.1.10
  @backstage/plugin-sonarqube                                      0.7.8
  @backstage/plugin-tech-radar                                     0.6.10
  @backstage/plugin-techdocs-backend                               1.9.0
  @backstage/plugin-techdocs-module-addons-contrib                 1.1.2
  @backstage/plugin-techdocs-node                                  1.10.0
  @backstage/plugin-techdocs-react                                 1.1.13
  @backstage/plugin-techdocs                                       1.9.0
  @backstage/plugin-todo-backend                                   0.3.5
  @backstage/plugin-todo                                           0.2.30
  @backstage/plugin-user-settings                                  0.7.12
  @backstage/release-manifests                                     0.0.10
  @backstage/test-utils                                            1.4.5
  @backstage/theme                                                 0.2.19, 0.3.0, 0.4.4
  @backstage/types                                                 1.1.1
  @backstage/version-bridge                                        1.0.7
Done in 0.38s.

Thanks!!

prasoon-pxc commented 10 months ago

any idea why it is like that, important thing is that it also works sometime, is yarn install --production --network-timeout 600000 cmd depends on some external dependencies which mis-behaves some time?

Getting one of them below errors :

Sometime this:

error An unexpected error occurred: "/app/node_modules/core-js: Cannot read properties of undefined (reading 'getOption')"

Sometime this:

error An unexpected error occurred: "/app/node_modules/core-js: Cannot read properties of undefined (reading 'config')".
germelindam commented 10 months ago

Any update on this, I'm running into the same issue while using docker image node:18-bookworm-slim and backstage version 1.18.0?

Shane-OH commented 10 months ago

https://github.com/backstage/backstage/issues/21381#issuecomment-1820366847

Im also seeing this error intermittently. Using node:18-bookworm-slim in my dockerfile. Any ways to fix this?

germelindam commented 10 months ago

What solved it for me was doing a yarn dependency update, after that didn't receive anymore errors. A lot of the dependencies we were using were outdated.

prasoon-pxc commented 10 months ago

@germelindam can you please share the cmd which you have used to solve this?

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.