cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.12k stars 3.19k forks source link

Error message printed to the console: Couldn't find tsconfig.json. tsconfig-paths will be skipped #22273

Open ptarczon opened 2 years ago

ptarczon commented 2 years ago

Current behavior

Similar issue as this but with version 10.1.0 Using a tsconfig.json in the cypress directory according to the documentation Run the command npx cypress open The output displays: Couldn't find tsconfig.json. tsconfig-paths will be skipped

Moving tsconfig.json to the root of the project helped but then another error was printed:

Missing baseUrl in compilerOptions. tsconfig-paths will be skipped

Adding "baseUrl": "./", to the compilerOptions made error disappear but not sure what is this baseUrl since documentation says baseUrl should be placed in cypress.config.ts

Desired behavior

No such error printed to the console.

Test code to reproduce

mkdir sample-project
cd sample-project
npm init --force
npm i --save-dev cypress typescript
npx cypress open --e2e --browser chrome
click continue button
quit cypress runner
cd cypress
touch tsconfig.json // paste contents in this file
cd ../
npx cypress open

contents of tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es5", "dom"],
    "types": ["cypress", "node"]
  },
  "include": ["**/*.ts"]
}

Logs:

❯ mkdir sample-project
❯ cd sample-project
❯ npm init --force
npm WARN using --force Recommended protections disabled.
Wrote to /Users/piotrtarczon/VSCprojects/sample-project/package.json:

{
  "name": "sample-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

❯ npm i --save-dev cypress typescript

added 166 packages, and audited 167 packages in 1s

27 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
❯ npx cypress open --e2e --browser chrome
objc[34125]: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffa4ead6318) and /Users/piotrtarczon/Library/Caches/Cypress/10.1.0/Cypress.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libGLESv2.dylib (0x111c759c8). One of the two will be used. Which one is undefined.
Couldn't find tsconfig.json. tsconfig-paths will be skipped
GET /__/ 200 7.732 ms - -
GET /__/assets/index.0128a075.css 200 5.049 ms - -
GET /__/assets/index.a96bfe29.js 200 70.632 ms - -
GET /chrome-variations/seed?osname=mac&channel=stable&milestone=102 304 673.540 ms - -
POST /ListAccounts?gpsia=1&source=ChromiumBrowser&json=standard 200 690.160 ms - -
GET /__cypress/runner/cypress_runner.css 200 3.085 ms - -
GET /__cypress/runner/cypress_runner.js 200 5.155 ms - -
GET /__/assets/Specs.ec514639.js 200 1.491 ms - 479
GET /__/assets/Index.8f76e9d7.css 200 4.905 ms - -
GET /__/assets/add-large_x16.34ef0540.js 200 7.495 ms - 753
GET /__/assets/Index.2108bd02.js 200 6.425 ms - -
GET /__/assets/SpecPatterns.5862fb95.js 200 9.320 ms - -
GET /__/assets/warning_x16.d9896e59.js 200 25.384 ms - -
GET /__/assets/CreateSpecModal.7b82dc44.js 200 15.439 ms - -
GET /__/assets/settings_x16.2429c71a.js 200 27.289 ms - -
GET /__/assets/cypress_s.29af549a.png 200 7.971 ms - 4425
GET /__/assets/chrome.1b5cb774.svg 200 1.342 ms - -
GET /__/assets/electron.fb07f5cc.svg 200 1.916 ms - -
GET /__/assets/firefox.9be61e66.svg 200 2.545 ms - -
GET /__cypress/runner/favicon.ico?v2 404 0.973 ms - 136
GET /__cypress/assets/favicon.png?v2 404 1.132 ms - 136
POST /v1:GetModels?key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw 200 766.750 ms - -
❯ cd cypress
❯ touch tsconfig.json
❯ cd ../
❯ npx cypress open
objc[34991]: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffa4ead6318) and /Users/piotrtarczon/Library/Caches/Cypress/10.1.0/Cypress.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libGLESv2.dylib (0x1124469c8). One of the two will be used. Which one is undefined.
Couldn't find tsconfig.json. tsconfig-paths will be skipped

Cypress Version

10.1.10

Other

No response

jennifer-shehane commented 2 years ago

Maybe duplicate of this: https://github.com/cypress-io/cypress/issues/21805

rachelruderman commented 2 years ago

@ptarczon thank you for reporting this issue!

To answer this question...

Adding "baseUrl": "./", to the compilerOptions made error disappear but not sure what is this baseUrl since documentation says baseUrl should be placed in cypress.config.ts

Both TypeScript and Cypress have a property called baseUrl in their respective config files, but they're different concepts 😸

Cypress baseUrl: "URL used as prefix for cy.visit() or cy.request() command's URL."

TypeScript baseUrl: "Lets you set a base directory to resolve non-absolute module names."

rachelruderman commented 2 years ago

This issue covers two topics:

  1. When TS is installed but no tsconfig.json is present, it logs Couldn't find tsconfig.json. tsconfig-paths will be skipped. #21805 is requesting that log be suppressed since nothing is necessarily wrong
  2. When TS is installed and tsconfig.json is added to the cypress root in accordance with the documentation, it logs Couldn't find tsconfig.json. tsconfig-paths will be skipped

I've created a repo here to reproduce the issue

oliverlockwood commented 2 years ago

I'm facing issue #2 as @rachelruderman described it. I have a tsconfig.json - I believe in the right place! - and want it to be used, but the error message appears. My E2Es seem to run OK so it might be benign, if a little disconcerting.

dante01yoon commented 2 years ago

I'm facing this issue too. I build docker image based on cypress/browsers:node14.17.6-slim-chrome100-ff99-edge, error occurred right after print cypress report, my pipeline assumes whole process is failed.

ShadowLNC commented 2 years ago

Adding "baseUrl": "./", to the compilerOptions made error disappear

This only seems to apply if tsconfig.json is in the root, as opposed to the Cypress folder.

If I put tsconfig.json in the Cypress folder (like Rachel's example and like the docs specify) then it seems to be ignored. Commenting or adding baseUrl has no effect on the error message.

If I put tsconfig.json in the root, then the error is suppressed. If I comment out my baseUrl declaration while tsconfig.json is in the root, I get the following:

Missing baseUrl in compilerOptions. tsconfig-paths will be skipped

Has Cypress 10 changed the expected location of tsconfig.json?

h2oearth commented 2 years ago

Why CY makes mandatory this tsconfig.json?. We do not use TS in some of our projects and CY keeps complaining about such file!

MikeMcC399 commented 2 years ago

I am seeing the warning message "Couldn't find tsconfig.json. tsconfig-paths will be skipped" on Cypress 10.7.0 after running npm install cypress@10.7.0 from a project which was previously running Cypress 9.7.0. The Cypress test specs are purely JavaScript. There are no *.ts files in the Cypress folders.

On the first run of npx cypress open on Cypress 10.7.0 the warning message "Couldn't find tsconfig.json. tsconfig-paths will be skipped" is displayed, before any Cypress 10 migration steps in the Cypress console have been carried out.

npx cypress open run with Cypress 9.7.0 does not output this message. I did however confirm that npx cypress open run with Cypress 10.0.0 also produces the warning message.

The warning message does not seem to affect the successful running of E2E tests written in JavaScript (*.js).

The problem is reproducible on Windows 10 and Windows 11 with Cypress 10.7.0. On Ubuntu 20.04 / 22.04 I could only reproduce with Cypress 10.0.0, not with Cypress 10.11.0.

MikeMcC399 commented 2 years ago

Following on from https://github.com/cypress-io/cypress/issues/22273#issuecomment-1242963302:

Uninstalling npm package browser-sync caused the warning message "Couldn't find tsconfig.json. tsconfig-paths will be skipped" on Cypress 10.7.0 to go away. browser-sync pulls in the npm package TypeScript and in my case uninstalling browser-sync also uninstalled typescript.

Before uninstall:

$ npm ls typescript
└─┬ browser-sync@2.27.10
  └─┬ browser-sync-client@2.27.10
    └── typescript@4.9.3

With no typescript installed there was then no warning message.

Unfortunately for me this is not a solution, only a helpful troubleshooting step.

As @h2oearth mentioned, I don't think that this warning should appear if the Cypress test specs do not include any TypeScript modules. The presence of an installed npm TypeScript module on its own should not trigger the warning.

If this should be recorded as a separate issue, please let me know.

Edit: Confirmed that issue still exists in Cypress 12.2.0, however I am now having difficulty to get the issue to reproduce reliably 🙁.


Repro steps:

npm install -D cypress@latest npx cypress open Click E2E Testing Click Continue exit Cypress

npx cypress open note no error exit Cypress

npm install -D browser-sync npx cypress open "Couldn't find tsconfig.json. tsconfig-paths will be skipped"

jasondavis87 commented 2 years ago

I'm not sure if i'm doing this right but using @rachelruderman post:

@ptarczon thank you for reporting this issue!

To answer this question...

Adding "baseUrl": "./", to the compilerOptions made error disappear but not sure what is this baseUrl since documentation says baseUrl should be placed in cypress.config.ts

Both TypeScript and Cypress have a property called baseUrl in their respective config files, but they're different concepts 😸

Cypress baseUrl: "URL used as prefix for cy.visit() or cy.request() command's URL."

TypeScript baseUrl: "Lets you set a base directory to resolve non-absolute module names."

I have 2 tsconfig.json files. One in the root of my project and one in the /cypress folder. I added baseUrl to the one in the root folder and the error goes away. the tsconfig.json in the cypress folder is just as the documentation said it should be:

/tsconfig.json

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true,
    "baseUrl": "."
  }
}

/cypress/tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es5", "dom"],
    "types": ["cypress", "node"],
  },
  "include": ["**/*.ts"]
}

Hope This helps someone

segevfiner commented 2 years ago

Newer tsconfig-paths changed the way this is done so this error shouldn't happen anymore if Cypress will upgrade. (It handles "baseDir": undefined properly instead of requiring it)

MikeMcC399 commented 2 years ago

@segevfiner

Newer tsconfig-paths changed the way this is done so this error shouldn't happen anymore if Cypress will upgrade.

Do you know what the minimum version of tsconfig-paths would be needed to resolve the issue in Cypress? I can see that the latest version is 4.1.0 whereas for instance Cypress seems to be using 3.10.1:

https://github.com/cypress-io/cypress/blob/bf6a52ab3d6b674985042c2871be4f36ade7652a/packages/server/package.json#L188

segevfiner commented 2 years ago

4.0.0+ but 4.1.0 fixed some bugs. They published a changelog.

MikeMcC399 commented 1 year ago
MikeMcC399 commented 1 year ago

@segevfiner

Your suggestion (which I quoted) has been picked up in https://github.com/cypress-io/cypress/issues/25335#issuecomment-1371268783, so hopefully there will be some further movement on this issue soon.

vsDizzy commented 1 year ago

This is bad experience when I'm following the cookbook and facing this error. Please fix either the documentation or the code.

yabab commented 1 year ago

This annoyed me so much I actually went and created another tsconfig.json in the project's root (used it to store general settings not directly related to Cypress and set a baseUrl) and used the tsconfig.json located in the cypress/ folder to extend the one in the project's root. Message no longer appears and checked that Cypress is correctly using data from both files.

shaharb-hs commented 1 year ago

Also encountered. Why not fix it? It's been open since June 2022 and still getting attention

shoaibshebi commented 1 year ago

Just uninstalled the cypress. Deleted the file and folders it generated and then again run the command to install cypress. Then I run just put cypress in my pakcage.json file of react project created by CRA:

"scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build", "test": "react-app-rewired test", "eject": "react-app-rewired eject", "cypress": "cypress open" }, and run "npm run cypress" in the terminal and cypress just ran, and them I click on the component testing and then cypress just setup all the files and folders on my project automatically, and all went good Thanks @FerdinandFidel

NickHeiner commented 1 year ago

This error message is confusing. It's not clear what the implication is. My test seems to run fine.

temrb commented 1 year ago

after adding "baseUrl": "." in tsconfig from comments warning dissappears. I'm guessing that is the issue

segevfiner commented 1 year ago

It's a limitation of an old version of tsconfig-paths. It is no longer needed in >4 should cypress finally update.

Raihanhn commented 1 year ago

After run "npx cypress open" getting this error

C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules\@opentelemetry\core\build\src\platform\node\environment.js:27 HOSTNAME: os.hostname(), ^ SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_gethostname returned ENOSYS (function not implemented) at getEnv (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules\@opentelemetry\core\build\src\platform\node\environment.js:27:22) at Object. (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules\@opentelemetry\sdk-trace-base\build\src\config.js:25:31) at Module._compile (node:internal/modules/cjs/loader:1103:14) at Module._extensions..js (node:internal/modules/cjs/loader:1155:10) at Object.require.extensions. [as .js] (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules\ts-node\dist\index.js:851:20) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules\@opentelemetry\sdk-trace-base\build\src\utility.js:19:18) { code: 'ERR_SYSTEM_ERROR', info: { errno: -4054, code: 'ENOSYS', message: 'function not implemented', syscall: 'uv_os_gethostname' }, errno: [Getter/Setter], syscall: [Getter/Setter] }

MikeMcC399 commented 1 year ago

@Raihanhn

You problem does not seem to be related to the original issue "Error message printed to the console: Couldn't find tsconfig.json. tsconfig-paths will be skipped". You may need to open a new issue.

Are you using one of the Node.js versions supported by Cypress? (14) 16, 18 or later? Which type of host are you running under?

Raihanhn commented 1 year ago

I am using nodejs version 16.

MikeMcC399 commented 1 year ago

@Raihanhn Could you give the name and version of your operating system as well?

Raihanhn commented 1 year ago

Windows 7, 64-bit

MikeMcC399 commented 1 year ago

@Raihanhn

The Cypress.io team will need to check, however https://learn.microsoft.com/en-us/lifecycle/products/windows-7 shows that Microsoft no longer supports this version of Microsoft Windows.

Your problem is indeed a completely separate issue from the one you have tagged on to here.

Raihanhn commented 1 year ago

Okay.Thanks for your info.

Churs82 commented 1 year ago

After run "npx cypress open" getting this error

C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules@opentelemetry\core\build\src\platform\node\environment.js:27 HOSTNAME: os.hostname(), ^ SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_gethostname returned ENOSYS (function not implemented) at getEnv (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules@opentelemetry\core\build\src\platform\node\environment.js:27:22) at Object. (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules@opentelemetry\sdk-trace-base\build\src\config.js:25:31) at Module._compile (node:internal/modules/cjs/loader:1103:14) at Module._extensions..js (node:internal/modules/cjs/loader:1155:10) at Object.require.extensions. [as .js] (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules\ts-node\dist\index.js:851:20) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules@opentelemetry\sdk-trace-base\build\src\utility.js:19:18) { code: 'ERR_SYSTEM_ERROR', info: { errno: -4054, code: 'ENOSYS', message: 'function not implemented', syscall: 'uv_os_gethostname' }, errno: [Getter/Setter], syscall: [Getter/Setter] }

The workaround is to go to C:\Users\user\AppData\Local\Cypress\Cache\12.11.0\Cypress\resources\app\node_modules@opentelemetry\core\build\src\platform\node\environment.js (you can click it in VSC console) and change os.hostname() to hardcoded name of your machine . Node.js above 14 use new version of libuv which is not compatible with windows 7 . So you can install modern node.js with ignorance of OS requirements but you cant use os.hostname() in your code or in libraries.

edudelta commented 1 year ago

I'm facing same issue running

cypress/tsconfig.json exists but "Couldn't find tsconfig.json. tsconfig-paths will be skipped"

yassinesos commented 1 year ago

I performed the following steps, and the error message disappeared:

Navigate to the AppData\Roaming\Cypress\cy\production\projects directory. Locate your project folder within this directory. Delete the project folder from the directory. Attempt to open Cypress again and see if the issue is resolved.

theTestingApproach commented 1 year ago

This is still happening in 12.12.0 my tsconfig.json file is in my cypress folder. I am getting "Unresolved function or method describe() " in all my cypress tests. And i get this too in the pipeline: Couldn't find tsconfig.json. tsconfig-paths will be skipped Any solution so far for this apart placing the tsconfig.json in the root of the project

jamaybyrone commented 1 year ago

Not sure if this helps anyone, but for me changing: "moduleResolution": "bundler"

in tsconfig to: "moduleResolution": "node"

resolved the issue

JackPaulssen commented 11 months ago

I'm seeing the same error, "Couldn't find tsconfig.json. tsconfig-paths will be skipped" having installed Typescript globally on my machine for a different project, despite not using Typescript on this specific Cypress project.

Unsure how to resolve.

only4arunkumar commented 8 months ago

Hello , for me the issue get resolved when i launch cypress using sudo command on mac. sudo npm i -f <> sudo npx cypress open

ddnexus commented 5 months ago

Simple workaround: use a minimal workspace.

Create a container dir in your project (sort of a sub-project that just runs the cypress tests) and put inside it: the cypress dir, a minimal package.json (no dependencies in it, so no node_modules dir), the cypress.config.ts, the tsconfig.json, etc.

It works and it's tidier (see the dir/workspace structure here)