Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/CD runs fail: Type Error: URL.canParse is not a function #474

Closed
jono-pov opened this issue May 2, 2024 · 7 comments
Closed

CI/CD runs fail: Type Error: URL.canParse is not a function #474

jono-pov opened this issue May 2, 2024 · 7 comments

Comments

@jono-pov
Copy link

jono-pov commented May 2, 2024

I'm not sure exactly when or how this issue started. But all my CI/CD runs using CorePack and PNPM are currently failing:

Type Error: URL.canParse is not a function
    at parseSpec (/opt/hostedtoolcache/node/20.12.2/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:23627:21)
    at loadSpec (/opt/hostedtoolcache/node/20.12.2/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:23704:11)
    at async findProjectSpec (/opt/hostedtoolcache/node/20.12.2/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:23649:20)
    at async executePackageManagerRequest (/opt/hostedtoolcache/node/20.12.2/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:24223:18)
    at async BinaryCommand.validateAndExecute (/opt/hostedtoolcache/node/20.12.2/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:21173:22)
    at async _Cli.run (/opt/hostedtoolcache/node/20.12.2/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:22148:18)
    at async Object.runMain (/opt/hostedtoolcache/node/20.12.2/x64/lib/node_modules/corepack/dist/lib/corepack.cjs:24279:12)
 ELIFECYCLE  Command failed with exit code 1.

Prior issues with this error (e.g. #394, #450) have been the result of using an older version of Node. However I'm running v20.12.2 and have tried v22 as well - the error happens either way.

@jono-pov
Copy link
Author

jono-pov commented May 2, 2024

The weird part is, the failure happens after the tasks where corepack is doing its thing.

This is my pipeline script:

pool:
  vmImage: ubuntu-latest

variables:
  pnpm_config_cache: $(Pipeline.Workspace)/.pnpm-store

steps:
  - task: UseNode@1
    inputs:
      version: "20.x"
    displayName: "Install Node.js"

  - task: Cache@2
    inputs:
      key: 'pnpm | "$(Agent.OS)" | ./src/ui/pnpm-lock.yaml'
      path: $(pnpm_config_cache)
    displayName: Cache pnpm

  - script: |
      corepack enable
      corepack prepare pnpm@latest-8 --activate
    displayName: "Setup pnpm"

  - script: pnpm config set store-dir $(pnpm_config_cache)
    displayName: "Setup pnpm caching"

  - script: |
      cd src/ui
      pnpm install
    displayName: "Install PNPM packages"

  - script: |
      node -v
      pnpm -v
      cd src/ui
      pnpm fastbuild
    displayName: "Build UI"

The "setup pnpm" step runs perfectly. The failure happens during the "build UI" step.

@jono-pov
Copy link
Author

jono-pov commented May 2, 2024

Prior issues with this error (e.g. #394, #450) have been the result of using an older version of Node. However I'm running v20.12.2 and have tried v22 as well - the error happens either way.

I may be wrong about this. As an experiment, I removed Corepack from the equation. After doing that, PNPM started giving me an error that I was only using node v16, despite explicitly installing v20 earlier in the pipeline.

Once I find a solution to that problem I'll update this issue.

@jono-pov
Copy link
Author

jono-pov commented May 3, 2024

Yep, never mind, it was a problem with my own setup using a different node version.

@jono-pov jono-pov closed this as completed May 3, 2024
@harrygr
Copy link

harrygr commented May 31, 2024

I'd love to know how you solved this as I have the same problem. I'm not using pnpm; just yarn. Here's my Github actions workflow:

 build-n-test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      # temporary fix for broken yarn
      - run: corepack enable
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: '19.8.1'
          cache: 'yarn'
      - run: yarn set version 3.5.0
      - run: yarn install
      - run: yarn test

@aduh95
Copy link
Contributor

aduh95 commented Jun 1, 2024

URL.canParse was added in Node.js v19.9.0, the failure is expected if you use an earlier (unsupported) version.

@harrygr
Copy link

harrygr commented Jun 1, 2024

ok, that makes sense. In my workflow the error was coming from corepack enable which needed to be run before the setup-node action, so it's being run with whatever Node version ubuntu-latest comes with (presumably < 19).

Solution is to move setup-node before corepack enable but this was breaking due to the yarn version specification in package.json not being met.

Removing cache: 'yarn' from the setup-node action fixed this.

@OP-Klaus
Copy link

URL.canParse is in v18 too https://nodejs.org/docs/latest-v18.x/api/url.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants