cypress-io / cypress

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

Cypress Object.statSync Error (Cannot read properties of undefined (reading 'uid')) #19674

Closed aidanhyland closed 2 years ago

aidanhyland commented 2 years ago

Current behavior

Today

Notes:

  1. Tried reinstalling cypress
  2. Tried clearing cypress cache
  3. Tried a new version of Cypress

TypeError: Cannot read properties of undefined (reading 'uid') at Object.statSync (C:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\graceful-fs\polyfills.js:303:17) at isDirectory (C:\Users\User\Documents\ADO\Nebula\Policy\tests\CypressTests\node_modules\resolve\lib\sync.js:22:23) at loadNodeModulesSync (C:\Users\User\Documents\ADO\Nebula\Policy\tests\CypressTests\node_modules\resolve\lib\sync.js:191:17) at Function.resolveSync [as sync] (C:\Users\User\Documents\ADO\Nebula\Policy\tests\CypressTests\node_modules\resolve\lib\sync.js:98:17) at Object.handler (C:\Users\User\Documents\ADO\Nebula\Policy\tests\CypressTests\cypress\plugins\index.js:13:27) at invoke (C:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:22:16) at C:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\util.js:45:14 at tryCatcher (C:\Users\User\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:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\method.js:39:29) at Object.wrapChildPromise (C:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\util.js:44:23) at Object.wrap (C:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\preprocessor.js:28:8) at execute (C:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:119:27) at EventEmitter.<anonymous> (C:\Users\User\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:202:5) at EventEmitter.emit (events.js:376:20) at process.<anonymous> (C:\Users\User\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:\Users\User\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)

Desired behavior

This obviously should not be happening

Test code to reproduce

Steps to reproduce described already

Cypress Version

8.7.0

Other

I see this issue with 8.7.0 & also 9.2.1

FelipeLahti commented 2 years ago

I'm having the same issue with a clean installation: Steps to reproduce:

npx create-react-app cypress-react-script-v5 --template typescript
npm i cypress @cypress/react @cypress/webpack-dev-server --save-dev
npx cypress open-ct

Node v16.13.0 cypress v9.2.1

FelipeLahti commented 2 years ago

I could workaround the error above by adding the below to package.json

"scripts": {
  "preinstall": "npx npm-force-resolutions",

 },
"resolutions": {
    "graceful-fs": "4.2.9"
}

BUT now, I'm getting a different error.

> cypress open-ct

TypeError: Ajv is not a constructor
    at Object.<anonymous> (/Users/felipelahti/clutch/front_end_financeapp/node_modules/react-scripts/node_modules/mini-css-extract-plugin/node_modules/schema-utils/dist/validate.js:66:13)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .js] (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/node_modules/ts-node/src/index.ts:529:44)
    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.<anonymous> (/Users/felipelahti/clutch/front_end_financeapp/node_modules/react-scripts/node_modules/mini-css-extract-plugin/node_modules/schema-utils/dist/index.js:6:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .js] (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/node_modules/ts-node/src/index.ts:529:44)
    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.<anonymous> (/Users/felipelahti/clutch/front_end_financeapp/node_modules/react-scripts/node_modules/mini-css-extract-plugin/dist/index.js:8:20)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .js] (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/node_modules/ts-node/src/index.ts:529:44)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
⚠️ Could not find Webpack options for react-scripts. Make sure that you have react-scripts module available.
Error: ⚠️ Could not find Webpack options for react-scripts. Make sure that you have react-scripts module available.
    at findReactScriptsWebpackConfig (/Users/felipelahti/clutch/front_end_financeapp/node_modules/@cypress/react/plugins/react-scripts/findReactScriptsWebpackConfig.js:20:11)
    at devServer (/Users/felipelahti/clutch/front_end_financeapp/node_modules/@cypress/react/plugins/react-scripts/index.js:12:20)
    at Object.handler (/Users/felipelahti/clutch/front_end_financeapp/node_modules/@cypress/react/plugins/utils/legacy-setup-dev-server.js:4:14)
    at invoke (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:22:16)
    at /Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:45:14
    at tryCatcher (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)
    at Object.wrapChildPromise (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:44:23)
    at Object.wrap (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/dev-server.js:21:8)
    at execute (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:117:24)
    at EventEmitter.<anonymous> (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:209:5)
    at EventEmitter.emit (node:events:390:28)
    at process.<anonymous> (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:19:22)
    at process.emit (node:events:390:28)
    at process.emit (/Users/felipelahti/Library/Caches/Cypress/9.2.1/Cypress.app/Contents/Resources/app/node_modules/source-map-support/source-map-support.js:495:21)
    at emit (node:internal/child_process:917:12)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)

Deps: "@cypress/react": "^5.12.1", "@cypress/webpack-dev-server": "^1.8.0", "react-scripts": "5.0.0", "react": "^17.0.2",

edikdeisling commented 2 years ago

I have this error too. It rises when I try to run cypress component tests with vite + vue.

It seems that for my case this error appeared after vite update. Don't know why Cypress at the end of error trace. Maybe Cypress incorrectly monkey patching some fs methods by using graceful-fs?

os: windows Cypress: 9.2.1 node: 16.13.2

 > ../../../../Users/Eduard/AppData/Local/Cypress/Cache/9.2.1/Cypress/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
        тХ╡                 ^
    at Object.statSync (C:\Users\Eduard\AppData\Local\Cypress\Cache\9.2.1\Cypress\resources\app\packages\server\node_modules\graceful-fs\polyfills.js:303:17)
    at isDirectory (C:\Projects\sit\rolos\frontend\node_modules\resolve\lib\sync.js:22:23)
    at loadNodeModulesSync (C:\Projects\sit\rolos\frontend\node_modules\resolve\lib\sync.js:191:17)
    at Function.resolveSync [as sync] (C:\Projects\sit\rolos\frontend\node_modules\resolve\lib\sync.js:98:17)
    at resolveFrom (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\utils.ts:85:18)
    at resolvePackageData (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\packages.ts:63:15)
    at C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\plugins\resolve.ts:522:11
    at Array.find (<anonymous>)
    at tryNodeResolve (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\plugins\resolve.ts:521:42)
    at Context.resolveId (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\plugins\resolve.ts:233:18)
    at Object.resolveId (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\server\pluginContainer.ts:478:47)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at resolve (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\optimizer\scan.ts:168:22)
    at C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\optimizer\scan.ts:336:28
    at callback (C:\Projects\sit\rolos\frontend\node_modules\esbuild\lib\main.js:832:28)
    at handleRequest (C:\Projects\sit\rolos\frontend\node_modules\esbuild\lib\main.js:664:30)

   node_modules/esbuild/lib/main.js:756:22: note: This error came from the "onResolve" callback registered here
    756 тФВ         let promise = setup({
        тХ╡                       ^
    at setup (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\optimizer\scan.ts:324:13)
    at handlePlugins (C:\Projects\sit\rolos\frontend\node_modules\esbuild\lib\main.js:756:23)
    at Object.buildOrServe (C:\Projects\sit\rolos\frontend\node_modules\esbuild\lib\main.js:1044:7)
    at C:\Projects\sit\rolos\frontend\node_modules\esbuild\lib\main.js:1895:17
    at new Promise (<anonymous>)
    at Object.build (C:\Projects\sit\rolos\frontend\node_modules\esbuild\lib\main.js:1894:14)
    at Object.build (C:\Projects\sit\rolos\frontend\node_modules\esbuild\lib\main.js:1749:51)
    at C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\optimizer\scan.ts:112:7
    at Array.map (<anonymous>)
    at scanImports (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\optimizer\scan.ts:111:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at optimizeDeps (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\optimizer\index.ts:160:27)
    at runOptimize (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\server\index.ts:564:40)
    at Server.httpServer.listen (C:\Projects\sit\rolos\frontend\node_modules\vite\src\node\server\index.ts:583:11)

   src/store/snackbar/index.ts:1:42: note: The plugin "vite:dep-scan" was triggered by this import
      1 тФВ import { ElNotification, ElMessage } from 'element-plus';
        тХ╡
edikdeisling commented 2 years ago

found an issue https://github.com/isaacs/node-graceful-fs/pull/220

aidanhyland commented 2 years ago

Hi,

We have resolved the issue on our side. There were conflicts with Typescript, cypress-cucumber-preprocessor & Cypress Tags.

const cucumber = require("cypress-cucumber-preprocessor").default; const browserify = require("@cypress/browserify-preprocessor"); const tagify = require("cypress-tags");

module.exports = (on, config) => { const options = { ...browserify.defaultOptions, typescript: require.resolve("typescript") };

on("file:preprocessor", (file) => {
    return file.filePath.includes(".feature") ? cucumber(options)(file) : tagify(config)(file);
});

};

"@cypress/browserify-preprocessor": "^3.0.2", "@testing-library/cypress": "^8.0.2", "@types/cypress-cucumber-preprocessor": "4.0.1", "@types/uuid": "^8.3.1", "cypress": "^9.2.1", "cypress-cucumber-preprocessor": "^4.3.1", "cypress-tags": "^0.3.0", "cypress-xpath": "^1.6.2",

Aidan

Vik4290 commented 2 years ago
Screenshot 2022-01-14 at 1 22 07 PM

I have same issue while using cypress along with cucumber bdd. Please find my package.json file.

============================================================================

{ "name": "package.json", "version": "1.0.0", "main": "index.js", "license": "MIT", "scripts": { "lint": "eslint 'cypress//*.{js,ts,tsx}'", "pretty": "prettier --write \"cypress/*/.{ts,js,jsx,json}\"" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.9.1", "@typescript-eslint/parser": "^5.9.1", "eslint": "^8.6.0", "eslint-config-airbnb-typescript": "^16.1.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-cypress": "^2.12.1", "eslint-plugin-import": "^2.25.4", "eslint-plugin-prettier": "^4.0.0", "prettier": "^2.5.1" }, "cypress:open": "cypress open", "dependencies": { "@cypress/browserify-preprocessor": "^3.0.2", "@types/chai-string": "^1.4.2", "@types/chai-subset": "^1.3.3", "@types/cypress-cucumber-preprocessor": "^4.0.1", "chai": "^4.3.4", "chai-string": "^1.5.0", "chai-subset": "^1.6.0", "cypress": "^9.2", "cypress-cucumber-preprocessor": "^4.3.1", "cypress-file-upload": "^5.0.8", "cypress-promise": "^1.1.0", "husky": "^7.0.4", "lint-staged": "^12.1.7", "tsify": "^5.0.4", "typescript": "^4.5.4", "uuidv4": "^6.2.12", "@testing-library/cypress": "^8.0.2", "@types/uuid": "^8.3.4", "cypress-tags": "^0.3.0" }, "husky": { "hooks": { "pre-commit": "lint-staged" } }, "lint-staged": { "./cypress//*.{js,ts}": [ "eslint --fix --max-warnings 0" ], "./*/.{json,md,yml}": [ "prettier --write" ] }, "cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true }, "resolutions": { "graceful-fs": "4.2.9" }

}

san-slysz commented 2 years ago

Same, producing after an update from a v7 to v9.2.1. We are using TypeScript & Cucumber.

TypeError: Cannot read properties of undefined (reading 'uid')

san-slysz commented 2 years ago

Doc in the cucumber repo changed. Changing my former code with the documented one solved it for me. I changed path.resolve('..') by path.resolve('.') because it suitted better my situation.

https://github.com/TheBrainFamily/cypress-cucumber-preprocessor#with-out-of-the-box-support

Hope it helps.

mdrie commented 2 years ago

Any work-around for vue + vite, yet?

Should this really be closed, just because there is a work-around?

edikdeisling commented 2 years ago

@mdrie I didn't test new release, but seems that 9.3.0 fixes this https://docs.cypress.io/guides/references/changelog#9-3-0

mdrie commented 2 years ago

@edikdeisling thanks, but no, that didn't help. I might have another problem. Might there be another problem with vue and/or vite?

edikdeisling commented 2 years ago

@mdrie If you have Cannot read properties of undefined (reading 'uid') error that means that you have package that depends on broken version of graceful-fs. You can try to scan your dependencies and find the package that doesn't migrate on the new version of graceful-fs yet.

mdrie commented 2 years ago

Seems I have another problem. graceful-fs is on 4.2.9 and in fact I do not get exactly that error, but "Cannot read properties of undefined (reading 'filter')"

filter is applied to an array within a state object which is retrieved from vuex store. The error only appears in cypress. When I do the same actions directly in the browser, everything works fine...

Should I open a new issue?

edikdeisling commented 2 years ago

Seems that you have issue in your code... Try to inverstigate why your store gives you undefined. Often there is some bugs when cypress "clicks" very fast and an app can't get in time. You can place cy.wait before cy actions to debug this case.

mdrie commented 2 years ago

Yes! Thank you. It was something completely different, but in the end - my problem. Thanks for the help!