Description
Current behavior
There are several issues (and PRs) related to this problem:
- fix(webpack-dev-server): touch component-index during onSpecsChange to avoid writing to app file #25861
- Custom location of cypress.config.ts crash on spec update in component tests #26400
- Error in absolute file path of component-index.html #27750
When setting an absolute path in the cypress.config.ts:
component: {
indexHtmlFile: <SOME ABSOLUTE PATH>,
}
an error is thrown as the indexHtml is expected to be in the project, not in some other (absolute) location:
Error: ENOENT: no such file or directory, utime 'C:\dev\project\libs\test\C:\dev\project\cypress\support\component-index.html'
at utimesSync (node:fs:2204:11)
at EventEmitter.CypressCTWebpackPlugin.onSpecsChange (C:\Users\user\AppData\Local\Cypress\Cache\14.4.0\Cypress\resources\app\node_modules\@packages\server\node_modules\@cypress\webpack-dev-server\dist\CypressCTWebpackPlugin.js:70:13)
at EventEmitter.emit (node:events:518:28)
at EventEmitter.emit (node:domain:489:12)
at EventEmitter.<anonymous> (C:\Users\user\AppData\Local\Cypress\Cache\14.4.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\dev-server.js:9:21)
at EventEmitter.emit (node:events:518:28)
at EventEmitter.emit (node:domain:489:12)
at process.<anonymous> (C:\Users\user\AppData\Local\Cypress\Cache\14.4.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\util.js:33:22)
at process.emit (node:events:518:28)
at process.emit (node:domain:489:12)
at process.emit.sharedData.processEmitHook.installedValue (C:\Users\user\AppData\Local\Cypress\Cache\14.4.0\Cypress\resources\app\node_modules\@cspotcode\source-map-support\source-map-support.js:745:40)
at process.emit (C:\dev\project\modules\frontend\node_modules\nx\src\native\index.js:20:23)
at emit (node:internal/child_process:949:14)
at processTicksAndRejections (node:internal/process/task_queues:91:21)
The issue lies in within how the indexHtmlFile path is created:
utimesSync(path.join(this.projectRoot, this.indexHtmlFile), new Date(), new Date())
There was another issue in another location with the same symptom. This has been fixed in #28324 by checking for an absolute path first.
I do not know enough about the code to fix this in a better way (as the TODO suggests...) but for the time being I want to suggest fixing it by also checking for an absolute path here. See attached MR.
Desired behavior
Absolute path for index Html file works correctly.
Test code to reproduce
I can try to do that if absolutely necessary but my time is a bit limited.
Cypress Version
14.4.0
Node version
v22.14.0
Operating System
Windows 10.0.19045.5737
Debug Logs
Other
No response