cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Yarn v4 DLX with TypeScript fails

Open mountainash opened this issue 10 months ago • 8 comments

Current behavior

Example: yarn dlx --package typescript --package cypress cypress run --config video=true in a clean project (without dependencies installed) should be about to run a test_name.cy.ts script.

Error: You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have 'typescript' installed to enable TypeScript support.

Desired behaviour

Should allow a way to specify the location of TypeScript (and other dependencies).

Test code to reproduce

  1. corepack enable (with a resent NodeJS version installed)
  2. yarn set version stable
  3. yarn dlx --package typescript --package cypress cypress run

Cypress Version

v14.0.2

Node version

v20.12.2

Operating System

macOS 15.3

Debug Logs

➤ YN0000: · Yarn 4.6.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + cypress@npm:14.0.2, typescript@patch:typescript@npm%3A5.7.3#optional!builtin<compat/typescript>::version=5.7.3&hash=5786d5, @colors/colors@npm:1.5.0, @cypress/request@npm:3.0.7, and 172 more.
➤ YN0000: └ Completed in 0s 653ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 176 packages were added to the project (+ 66.83 MiB).
➤ YN0000: └ Completed in 0s 202ms
➤ YN0000: ┌ Link step
➤ YN0007: │ cypress@npm:14.0.2 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 1s 217ms
➤ YN0000: · Done in 2s 94ms


DevTools listening on ws://127.0.0.1:53311/devtools/browser/ef0e6d53-9f4a-4202-bb8c-dd781bfdbd12

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        14.0.2                                                                         │
  │ Browser:        Electron 130 (headless)                                                        │
  │ Node Version:   v20.12.2 (/usr/local/bin/node)                                                 │
  │ Specs:          1 found (claim.cy.ts)                                                          │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

Other

There are numerous discussions, issues and PRs relating to PnP and Yarn (modern/v3/v4) [and Bun] due to the lookup/reference issues of dependencies in Cypress.

This instruction in this issue should make it easier for project Contributors to replicate the issue with minimum environment noise.

mountainash avatar Feb 11 '25 14:02 mountainash

@mountainash Why are you wanting to use dlx for cypress as opposed to adding it as a dependency?

jennifer-shehane avatar Feb 11 '25 14:02 jennifer-shehane

The issue is that Cypress's post install script is very time consuming (~20 seconds): which is expensive esp for workflows where it [Cypress] isn't used. [which is what happens when yarn install or yarn add cypress is used in a project with cypress as a dependency]

It makes sense to install and run Cypress only when it's needed. [which is what happens when yarn dlx cypress is used in a project without cypress as a dependency, but with Cypress test scripts]

mountainash avatar Feb 11 '25 15:02 mountainash

@mountainash

You may find that setting the environment variable

CYPRESS_INSTALL_BINARY=0

meets your needs to suppress the Cypress binary download.

See https://docs.cypress.io/app/references/advanced-installation#Skipping-installation

MikeMcC399 avatar Feb 11 '25 15:02 MikeMcC399

@MikeMcC399 thank you for the suggestion. That would work in some automated scenarios, but it's not too instinctive to do for every Developer to have to add that before the muscle memory of yarn install or just yarn.

Also this issue was to help the project contributors to help debug the Yarn PnP/Cypress/"node_modules" linking issues in a cleaner/isolated way - which may help solve the grander issues.

mountainash avatar Feb 11 '25 16:02 mountainash

@mountainash

I was not able to reproduce your issue based on your description and I did not receive any TypeScript related error message when I tried. Your description does not include the TypeScript, Yarn and Cypress configuration and so there is room for interpretation.

Can you provide a complete online example repo with your configuration? You can fork https://github.com/cypress-io/cypress-test-tiny and use this repo.

MikeMcC399 avatar Feb 12 '25 07:02 MikeMcC399

Thank @MikeMcC399 for trying it out... so it seems it could be my configuration. I don't have time ATM to set-up an isolated test (internally we reverted to just installing the whole project with yarn install - as it's not a massive/urgent issue). If I get some time I'll attempt to isolate the problem. Has anyone had success in running Cypress on a CodeSandBox VM? [asking as it's then easier to share and very the code without security issues on your local machine]

mountainash avatar Feb 12 '25 09:02 mountainash

@mountainash

Has anyone had success in running Cypress on a CodeSandBox VM?

You can ask questions like this in the Cypress technical community on Discord

Discord chat (click on button)

You can use https://github.com/cypress-io/cypress-test-tiny or a repo of your own choosing in order to share a reproduction of your issue.

MikeMcC399 avatar Feb 12 '25 09:02 MikeMcC399

I suggest to close this issue, since without further information it is not actionable at this time.

MikeMcC399 avatar Feb 13 '25 20:02 MikeMcC399

No worries. I might return to this when I find time in the future. Thanks for your help @MikeMcC399

mountainash avatar Feb 19 '25 21:02 mountainash