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

Component testing with Vite is failing due to the outdated bundled graceful-fs version #19610

Closed
sodatea opened this issue Jan 7, 2022 · 16 comments

Comments

@sodatea
Copy link
Contributor

sodatea commented Jan 7, 2022

Current behavior

Component testing with Vite in new projects doesn't work.
There will be errors like:

[vite] Internal server error: Cannot read properties of undefined (reading 'uid') Failed to fetch dynamically imported module: http://localhost:3001/src/components/__tests__/HelloWorld.spec.js?import

The direct cause is the latest version of resolve. It exposes a bug in older versions of graceful-fs.
Because Cypress bundles graceful-fs by itself, there seems no way for users to fix it by themselves.

More technical details is explained at browserify/resolve#264 (comment)

Desired behavior

Update the bundled graceful-fs version to >= 4.2.9

Test code to reproduce

https://github.com/robyedlin/vue3-starter

Cypress Version

9.2.0

Other

No response

@sodatea sodatea changed the title Component testing with Vite is failing due to the outdated bundled graceful-js version Component testing with Vite is failing due to the outdated bundled graceful-fs version Jan 7, 2022
@sainthkh sainthkh added the stage: ready for work The issue is reproducible and in scope label Jan 10, 2022
@sainthkh
Copy link
Contributor

Confirmed that it doesn't work. Thanks for the reproducible example.

@ljharb
Copy link

ljharb commented Jan 10, 2022

A better solution than just updating the bundled version is to not bundle dependencies at all :-)

@NitinMalave20
Copy link

NitinMalave20 commented Jan 10, 2022

Using Cypress 8.7.0 in Angular 12.2.0 application & I have been facing the similar issue since last 3 days. Please let me know in case any fix exist for the issue.

I think it is due to incompatibility caused by upgradation of internal packages i.e. of graceful-fs & resolve , Any help would be appreciated on the issue, Thanks.

Attaching the detail log of the issue,

`
The function exported by the plugins file threw an error.

We invoked the function exported by C:\\\e2e\cypress\plugins\index.js, but it threw an error.

TypeError: Cannot read properties of undefined (reading 'uid')
at Object.statSync (C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\graceful-fs\polyfills.js:303:17)
at isDirectory (C:\node_modules\resolve\lib\sync.js:22:23)
at loadNodeModulesSync (C:\node_modules\resolve\lib\sync.js:191:17)
at Function.resolveSync [as sync] (C:\node_modules\resolve\lib\sync.js:98:17)
at module.exports (C:\\e2e\cypress\plugins\index.js:8:25)
at C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:90:12
at tryCatcher (C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\util.js:16:23)
at Function.Promise.attempt.Promise.try (C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\method.js:39:29)
at load (C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:87:7)
at EventEmitter. (C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:198:5)
at EventEmitter.emit (events.js:376:20)
at process. (C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\util.js:19:22)
at process.emit (events.js:376:20)
at process.emit (C:\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\source-map-support\source-map-support.js:495:21)
at emit (internal/child_process.js:910:12)
at processTicksAndRejections (internal/process/task_queues.js:83:21)
`

@bhvngt
Copy link

bhvngt commented Jan 11, 2022

Any update on this issue? This is breaking even the older version of cypress possibly due to buggy dependency. In the long term, it might help to remove this dependency as the author suggest

@yeongsheng-tan
Copy link

You may force the transitive dependency of resolve to version 1.20.0 in your package.json.
E.g.:

  "devDependencies": {
    "@testing-library/cypress": "8.0.2",
    "@types/node": "^17.0.2",
    "browserify": "^17.0.0",
    "cy-verify-downloads": "^0.0.5",
    "cypress": "9.2.1",
    "cypress-cucumber-preprocessor": "4.3.1",
    "cypress-file-upload": "5.0.8",
    "file-saver": "^2.0.5",
    "got": "^12.0.1",
    "npm-run-all": "4.1.5",
    "prettier": "^2.5.0",
    "tsify": "5.0.4",
    "typescript": "^3.9"
  },
  "resolutions": {
    "resolve": "1.20.0"
  }

@ljharb
Copy link

ljharb commented Jan 11, 2022

That’s not a helpful suggestion.

You can use next@12.0.8-canary, 19 or higher, and it should be fixed.

@bhvngt
Copy link

bhvngt commented Jan 11, 2022

Since this the dependencies are bundled up with cypress app, the overrides in local package.json will not work in this case.

@ljharb I am using svelte. In any case it does not matter because of the above reason.

@ljharb
Copy link

ljharb commented Jan 11, 2022

@bhvngt ah, and does svelte bundle graceful-fs also? If so, can you link me to the issue filed on it? (or does svelte depend on cypress which bundles it, and that’s the problem)

@bhvngt
Copy link

bhvngt commented Jan 11, 2022

@ljharb the issue has nothing to do with svelte.

In my case it is getting thrown from the Cypress app bundle. Cypress app bundles graceful-fs from where this error is thrown. Here's the error snippet that shows the source of the error.

Opening Cypress...
 > ../../../../../Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/polyfills.js:303:16: error: [plugin: vite:dep-scan] Cannot read properties of undefined (reading 'uid')
    303 │       if (stats.uid < 0) stats.uid += 0x100000000

@ljharb
Copy link

ljharb commented Jan 11, 2022

then in that case, i hope cypress fixes it soon.

@erikrahm
Copy link

erikrahm commented Jan 11, 2022

Any update on this? Happening for me as well using cypress w/ react.

The only workaround I've found is using an old version of node specifically v12.22.1 for me. Hope that helps you all in the meantime.

@bhvngt
Copy link

bhvngt commented Jan 12, 2022

Code digging suggests that graceful-fs package installed under server throws this error. It needs to be upgraded from 4.2.0 to 4.2.9.

@Assael1
Copy link

Assael1 commented Jan 12, 2022

Is there something i can do for now? someone found a work around until it's fixed?
BTW, i'm not using Vite and it still happens to me (only in CI environment, on local I can't reproduce it).

@mjhenkes
Copy link
Member

PR to update graceful-fs version: #19676

@chrisbreiding
Copy link
Contributor

The code for this is done, but has yet to be released. We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 18, 2022

Released in 9.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.3.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: ready for work The issue is reproducible and in scope label Jan 18, 2022
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jan 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants