nx: Cypress open fails with "Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig"
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.
- Generate a sample project for cypress with nx.
- 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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 15 (1 by maintainers)
Is the any plan to change something here? Using
ng e2e test-e2eorcypresscli is better option than onlyng e2e test-e2eHi @CSchulz, you can run e2e tests with
ng e2e test-e2e, or you can useyarn/npmif you don’t use a globalngbin.We don’t recommend using the
cypresscli directly since will not have the correct config.TL;DR aka the solution
Add below to your project-e2e/cypress.json file (no need to do it index.js as https://github.com/nrwl/nx/issues/1707#issuecomment-520896834 suggests):
Debug summary
You get error:
Error: Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfigYou follow advice from https://github.com/nrwl/nx/issues/1707#issuecomment-520896834 . Now you get
TypeError: path argument is required to res.sendFile.Based on https://github.com/nrwl/nx/issues/1707#issuecomment-863600209 suggestion, you remove changes to you index.js and add below to your
cypress.json:Now you get error
TypeError: err.replace is not a function. (if you added ./ like me - otherwise you might have success here.)By going to
node_modules/@cypress/webpack-preprocessor/index.js:230:16as 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..You search the error and find the solution here: https://github.com/TypeStrong/ts-loader/issues/405#issuecomment-330108362
You remove the ‘./’ from “tsConfig”: “./tsconfig.json” you added earlier in
cypress.json, so it becomes"tsConfig": "tsconfig.json".Et viola - tests now work. Hopefully…
Here is another use case: I wish to run tests against deployed app without building it first, e.g. by passing baseUrl
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
Changing the plugin.js to set the tsconfig.json if not set works partial:
It shows all tests now, but if you run a test now, it fails with another message:
I am using Cypress 3.4.1.
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.
@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