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

Cypress open fails with "Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig" #1707

Closed
CSchulz opened this issue Aug 13, 2019 · 15 comments

Comments

@CSchulz
Copy link

CSchulz commented Aug 13, 2019

Expected Behavior

It should use the existing tsconfig.json.

Current Behavior

It fails because there is no tsconfig.json defined in the config.

Failure Information (for bugs)

Error: Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig
    at preprocessTypescript (nx/myworkspace/node_modules/@nrwl/cypress/src/plugins/preprocessor.js:8:15)
    at module.exports (nx/myworkspace/apps/test-e2e/src/plugins/index.js:21:27)
    at Promise.try (Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:62:12)
    at tryCatcher (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)
    at load (Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:61:7)
    at EventEmitter.ipc.on (Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:132:5)
    at emitOne (events.js:116:13)
    at EventEmitter.emit (events.js:211:7)
    at process.<anonymous> (Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:25:29)
    at emitTwo (events.js:126:13)
    at process.emit (events.js:214:7)
    at emit (internal/child_process.js:772:12)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Generate a sample project for cypress with nx.
  2. Run npx cypress -P apps/test-e2e

Context

  • Nx: 8.4.8
Angular CLI: 8.1.1
Node: 10.15.3
OS: darwin x64
Angular: 8.2.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.801.1
@angular-devkit/build-angular     0.800.6
@angular-devkit/build-optimizer   0.800.6
@angular-devkit/build-webpack     0.800.6
@angular-devkit/core              8.1.1
@angular-devkit/schematics        8.1.1
@angular/cli                      8.1.1
@ngtools/webpack                  8.0.6
@schematics/angular               8.1.1
@schematics/update                0.801.1
rxjs                              6.4.0
typescript                        3.4.5
webpack                           4.30.0
@CSchulz
Copy link
Author

CSchulz commented Aug 13, 2019

Changing the plugin.js to set the tsconfig.json if not set works partial:

  on('file:preprocessor', () => {
    if (!config.env.tsConfig) {
      config.env.tsConfig = config.fileServerFolder + '/tsconfig.json';
    }
    return preprocessTypescript(config);
  });

It shows all tests now, but if you run a test now, it fails with another message:

GET /__/ 200 29.461 ms - -
GET /__cypress/runner/cypress_runner.css 200 22.230 ms - -
GET /__cypress/runner/cypress_runner.js 200 500.607 ms - -
GET /__cypress/static/favicon.ico 200 2.382 ms - -
GET /__cypress/iframes/integration/app.spec.ts 200 8.190 ms - 613
GET /__cypress/runner/fonts/fontawesome-webfont.woff2?v=4.7.0 200 4.772 ms - 77160
TypeError: path argument is required to res.sendFile
    at ServerResponse.sendFile (Cypress.app/Contents/Resources/app/packages/server/node_modules/express/lib/response.js:411:11)
    at tryCatcher (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at ret (<anonymous>:14:23)
    at Cypress.app/Contents/Resources/app/packages/server/lib/controllers/spec.js:29:16
    at tryCatcher (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:691:18)
    at Async._drainQueue (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

GET /__cypress/tests?p=src/integration/app.spec.ts-218 200 6.698 ms - 165
HEAD / - - ms - -
HEAD / - - ms - -
HEAD / - - ms - -

I am using Cypress 3.4.1.

@jaysoo
Copy link
Member

jaysoo commented Aug 15, 2019

Hi @CSchulz, you can run e2e tests with ng e2e test-e2e, or you can use yarn/npm if you don't use a global ng bin.

We don't recommend using the cypress cli directly since will not have the correct config.

@jaysoo jaysoo closed this as completed Aug 15, 2019
@expcapitaldev
Copy link

Is the any plan to change something here?
Using ng e2e test-e2e or cypress cli is better option than only ng e2e test-e2e

@ninogomez
Copy link

@CSchulz Did you have a workaround for this? I'm getting the same "path argument is required to res.sendFile" message when I run the test. Thanks!

@nicolalopatriello
Copy link

Any news? Some issue in my project.

@imadhy
Copy link

imadhy commented Sep 30, 2020

Hi @CSchulz, you can run e2e tests with ng e2e test-e2e, or you can use yarn/npm if you don't use a global ng bin.

We don't recommend using the cypress cli directly since will not have the correct config.

How do you do then to launch e2e test on a CI ? I haven't seen any example to do this and the only way I've seen personally is to try the official Cypress approach using cypress run command as the ng e2e fail on CI

@mac2000
Copy link

mac2000 commented Nov 26, 2020

Here is another use case: I wish to run tests against deployed app without building it first, e.g. by passing baseUrl

@Elif5757
Copy link

@CSchulz @ninogomez I'm getting the same "path argument is required to res.sendFile" message when I run the test. What should I do?

@CSchulz
Copy link
Author

CSchulz commented Jan 14, 2021

@Elif5757 Which versions are you using?

@Elif5757
Copy link

@CSchulz

"@angular-devkit/build-angular": "^0.1002.0",
"@angular-eslint/eslint-plugin": "^0.6.0-beta.0",
"@angular-eslint/eslint-plugin-template": "^0.6.0-beta.0",
"@angular-eslint/template-parser": "^0.6.0-beta.0",
"@angular/cli": "~10.1.3",
"@angular/compiler-cli": "^10.1.0",
"@angular/language-service": "^10.1.0",
"@cypress/code-coverage": "^1.12.2",
"@cypress/webpack-preprocessor": "^5.4.11",
"ts-loader": "^8.0.11",
"ts-node": "^7.0.1",
"typescript": "~4.0.3"
"@angular-devkit/build-angular": "^0.1002.0",
"@angular-eslint/eslint-plugin": "^0.6.0-beta.0",
"@angular-eslint/eslint-plugin-template": "^0.6.0-beta.0",
"@angular-eslint/template-parser": "^0.6.0-beta.0",
"@angular/cli": "~10.1.3",
"@angular/compiler-cli": "^10.1.0",
"@angular/language-service": "^10.1.0",
"@cypress/code-coverage": "^1.12.2",
"@cypress/webpack-preprocessor": "^5.4.11",
"ts-loader": "^8.0.11",
"ts-node": "^7.0.1",
"typescript": "~4.0.3"
"cypress": "^6.0.1",
"@nrwl/cli": "^10.3.3",
"@nrwl/cypress": "9.0.0",
"@nrwl/eslint-plugin-nx": "^10.3.3",
"@nrwl/jest": "^10.3.3",
"@nrwl/workspace": "^10.3.3",
"@types/jest": "26.0.8",
"@types/node": "~8.9.4",

@yjcyun
Copy link

yjcyun commented Jun 2, 2021

@Elif5757 were you able to resolve this error? I'm facing the same problem

@Elif5757
Copy link

Elif5757 commented Jun 8, 2021

@yjcyun hey I have solved the problem but i don't know the solution anymore. Find me on https://gitter.im/cypress-io/cypress
so i can help you there

@nghedia
Copy link

nghedia commented Jun 17, 2021

to solve the "path argument is required to res.sendFile" error. I needed to update the path for fileServerFolder in the cypress.json config. this path should point to the tsconfig.json in the e2e project folder.

@MartinJHammer
Copy link

MartinJHammer commented Aug 6, 2021

TL;DR aka the solution

Add below to your project-e2e/cypress.json file (no need to do it index.js as #1707 (comment) suggests):

{
  "env": {
    "tsConfig": "tsconfig.json"
  }
}

Debug summary

  1. You get error: Error: Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig

  2. You follow advice from Cypress open fails with "Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig" #1707 (comment) . Now you get TypeError: path argument is required to res.sendFile.

  3. Based on Cypress open fails with "Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig" #1707 (comment) suggestion, you remove changes to you index.js and add below to your cypress.json:

  "env": {
      "tsConfig": "./tsconfig.json"
  }

Now you get error TypeError: err.replace is not a function. (if you added ./ like me - otherwise you might have success here.)

  1. By going to node_modules/@cypress/webpack-preprocessor/index.js:230:16 as mentioned in above error stack and logging the error like shown in screenshot, you see the actual error needing fixing: TS18002: The 'files' list in config file 'tsconfig.json' is empty..
    image

  2. You search the error and find the solution here: typescript v2.1.4 doesn't like empty files in config TypeStrong/ts-loader#405 (comment)

  3. You remove the './' from "tsConfig": "./tsconfig.json" you added earlier in cypress.json, so it becomes "tsConfig": "tsconfig.json".

  4. Et viola - tests now work. Hopefully...

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests