#Unable to deploy application due to corepack issue

1 messages · Page 1 of 1 (latest)

green needle
#

Hi All! I am trying to deploy backstage application with jenkins however, I am running into corepack related errors. This is working locally but fails when I am using image 'node:20-bullseye' and running the below script

        container('node') {
            sh '''
            ls -l $(which yarn)
            curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
            export NVM_DIR="$HOME/.nvm"
            [ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh"
            [ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion"
            corepack enable
            corepack -v
            corepack prepare [email protected] --activate
            yarn set version 4.4.1
            yarn -v //just checking version
            '''
            sh 'yarn install --immutable'
            sh 'yarn tsc'```

This is the error I am running into -

```+ yarn install --immutable
15:25:00  error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22.
15:25:00  
15:25:00  Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
15:25:00  Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.```
#

Chatgpt suggested to use 'corepack yarn install' 'corepack yarn tsc' and so on instead of only 'yarn install' etc. However, doing so I am running into errors like

15:08:25  error TS2468: Cannot find global value 'Promise'.
15:08:25  packages/app/src/App.test.tsx(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations.
15:08:25  packages/app/src/App.test.tsx(2,33): error TS2307: Cannot find module '@testing-library/react' or its corresponding type declarations.
15:08:25  packages/app/src/App.test.tsx(3,17): error TS6142: Module './App' was resolved to '/home/jenkins/workspace/cloudops_backstage_image_MR-6/packages/app/src/App.tsx', but '--jsx' is not set.
15:08:25  packages/app/src/App.test.tsx(5,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
15:08:25  packages/app/src/App.test.tsx(6,3): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
15:08:25  packages/app/src/App.test.tsx(6,23): error TS2705: An async function or method in ES5 requires the 'Promise' constructor.  Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
15:08:25  packages/app/src/App.test.tsx(7,5): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
15:08:25  packages/app/src/App.test.tsx(23,29): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.```

Any help would be highly appreciated. Thanks!
harsh remnant
green needle
#

Yes, I did. For example, my existing setup is working with below

#

    container {
        name 'node'
        image 'node:20-bullseye'
        requests {
            cpu '2'
            memory '8Gi'
        }
    }

    setup {
        container('node') {
            sh 'yarn install --frozon-lockfile'
            sh 'yarn tsc'
            withEnv([
                "APP_BASE_URL=https://backstage.dev.com",
                "BACKEND_BASE_URL=https://backstage.dev.com",
            ]) {
                sh 'yarn build:backend'
            }
            sh 'cp ~/.npmrc .'
        }
    }

    dockerfile 'packages/backend/Dockerfile'

    mergeRequest {
        project 'cloudops/backstage/deploy'
        patch { context, project ->
            sh(
                script: [
                    'yq',
                    '--inplace',
                    "'(.spec.template.spec.containers.[]|select(.name==\"backstage\"))|=.image=\"$context.IMAGE:$context.VERSION\"'",
                    "$project/backstage/prod/backstage-deployment.yaml",
                ].join(' ')
            )
        }
        merge true
    }

}
#

But when I try to use corepack for the new backstage version, it starts failing ```cloudops.dockerImage {

container {
    name 'node'
    image 'node:20-bullseye'
    requests {
        cpu '2'
        memory '8Gi'
    }
}

setup {
    container('node') {
        sh '''
        ls -l $(which yarn)
        curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
        export NVM_DIR="$HOME/.nvm"
        [ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh"
        [ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion"
        corepack enable
        corepack -v
        corepack prepare [email protected] --activate
        yarn set version 4.4.1
        yarn -v
        ls -l $(which yarn)
        '''
        sh 'yarn install --immutable'
        sh 'yarn tsc'
        withEnv([
            "APP_BASE_URL=https://backstage.dev.com",
            "BACKEND_BASE_URL=https://backstage.dev.com",
        ]) {
            sh 'yarn build:backend'
        }
        sh 'cp ~/.npmrc .'
    }
}

dockerfile 'packages/backend/Dockerfile'

mergeRequest {
    project 'cloudops/backstage/deploy'
    patch { context, project ->
        sh(
            script: [
                'yq',
                '--inplace',
                "'(.spec.template.spec.containers.[]|select(.name==\"backstage\"))|=.image=\"$context.IMAGE:$context.VERSION\"'",
                "$project/backstage/prod/backstage-deployment.yaml",
            ].join(' ')
        )
    }
    merge true
}

}

green needle
#

I also tried installing corepack within a directory but that dint work either ```setup {
container('node') {
sh 'mkdir ~/corepack'
sh 'corepack enable --install-directory ~/corepack'
sh 'corepack prepare [email protected] --activate'
sh '~/corepack/yarn --version'
sh '~/corepack/yarn install --immutable'
sh '~/corepack/yarn tsc'
withEnv([
"APP_BASE_URL=https://backstage.dev.com",
"BACKEND_BASE_URL=https://backstage.dev.com",
]) {
sh '~/corepack/yarn build:backend'
}
sh 'cp ~/.npmrc .'
}
}

#

With this its able to proceed with yarn but starts throwing other errors like + corepack yarn tsc 15:08:25 error TS2468: Cannot find global value 'Promise'. 15:08:25 packages/app/src/App.test.tsx(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations. 15:08:25 packages/app/src/App.test.tsx(2,33): error TS2307: Cannot find module '@testing-library/react' or its corresponding type declarations. 15:08:25 packages/app/src/App.test.tsx(3,17): error TS6142: Module './App' was resolved to '/home/jenkins/workspace/cloudops_backstage_image_MR-6/packages/app/src/App.tsx', but '--jsx' is not set. 15:08:25 packages/app/src/App.test.tsx(5,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. 15:08:25 packages/app/src/App.test.tsx(6,3): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. 15:08:25 packages/app/src/App.test.tsx(6,23): error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. 15:08:25 packages/app/src/App.test.tsx(7,5): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. 15:08:25 packages/app/src/App.test.tsx(23,29): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.

dire edge
#

if you have any clue to solve it, please share it, I face the same issue, I think it is just env setting issue.

harsh remnant
#

I will check on my laptop later as well 🙏

green needle
#

This page https://backstage.io/docs/deployment/docker/ does not mention it but when you build the app on your local using [email protected] it adds below line to 'package.json' "packageManager": "[email protected]" so when I push the code & if I don't use corepack the build fails with message error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22. 12:37:32 12:37:32 Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19. 12:37:32 Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.

How to build a Backstage Docker image for deployment

green needle
dire edge
#

@green needle have you solved issue?

green needle
#

No. I am still facing this issue.

plucky rock
#

We don't use nvm in the build. I'm not sure where all of this is coming from 🤔

#

Do you copy .yarn and .yarnrc.yml into your image before running yarn install?

green needle
green needle
green needle
green needle
#

Is there any example you can point me to where we use corepack? Apologies if I wasn't clear with my doubt earlier. Thanks for the help!

green needle
#

Kindly disregard this thread. I was able to resolve this issue in my pipeline.

dire edge
#

@green needle how you resolve it, can you share with larger users?

green needle
#

It resolved after I installed corepack within a directory (this was the first issue wherein corepack was unable to activate specific yarn version & was conflicting with global yarn version of the image) and then I added this line at the end cp ~/.yarnrc.yml .home.yarnrc.yml which did the trick. This is my entire code block: ```setup {
container('node') {
sh 'mkdir ~/corepack'
sh 'corepack enable --install-directory ~/corepack'
sh '~/corepack/yarn install --immutable'
sh '~/corepack/yarn tsc'
withEnv([
"APP_BASE_URL=https://backstage.enablement.cloudops.fortradev.com",
"BACKEND_BASE_URL=https://backstage.enablement.cloudops.fortradev.com",
]) {
sh '~/corepack/yarn build:backend'
}
sh 'cp ~/.yarnrc.yml .home.yarnrc.yml'
}
}