I have a Cypress project with TypeScript support using the Cucumber Preprocessor and all of a sudden it started to throw the below exception:
TypeError: Cannot read properties of undefined (reading 'uid')
Some times it works when I change to a different workspace but again this error is reproducing when I open the Cypress runner itself and even when executing in Jenkins too.
Cypress Runner: (v8.4.0)
Jenkins Console: (v8.7.0)
The function exported by the plugins file threw an error.
We invoked the function exported by `C:\Jenkins\workspace\ABC\cypress\plugins\index.js`, but it threw an error.
TypeError: Cannot read properties of undefined (reading 'uid')
at Object.statSync (C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\graceful-fs\polyfills.js:303:17)
at isDirectory (C:\Jenkins\workspace\ABC\ui\node_modules\resolve\lib\sync.js:22:23)
at loadNodeModulesSync (C:\Jenkins\workspace\ABC\ui\node_modules\resolve\lib\sync.js:191:17)
at Function.resolveSync [as sync] (C:\Jenkins\workspace\ABC\ui\node_modules\resolve\lib\sync.js:98:17)
at module.exports (C:\Jenkins\workspace\ABC\ui\cypress\plugins\index.js:15:25)
at C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:90:12
at tryCatcher (C:\Windows\SysWOW64\config\systemprofile\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:\Windows\SysWOW64\config\systemprofile\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\method.js:39:29)
at load (C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Cypress\Cache\8.7.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:87:7)
at EventEmitter.<anonymous> (C:\Windows\SysWOW64\config\systemprofile\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.<anonymous> (C:\Windows\SysWOW64\config\systemprofile\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:\Windows\SysWOW64\config\systemprofile\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)
error Command failed with exit code 1.
plugins/index.js
const resolve = require('resolve');
const cucumber = require("cypress-cucumber-preprocessor").default;
const cypressBrowserify = require("@cypress/browserify-preprocessor");
const mysql = require('mysql2')
const db = require('../../cypress.json')
var mssql = require('mssql');
const path = require('path');
const fs = require('fs-extra');
const allureWriter = require('@shelex/cypress-allure-plugin/writer');
module.exports = (on, config) => {
const options = {
...cypressBrowserify.defaultOptions,
typescript: resolve.sync('typescript', {project: config.projectRoot}),
};
on("file:preprocessor", cucumber(options));
on('task', {
'createMySQLConnection'(query) {
var value = mysqlDB(query)
return value
}
});
function mysqlDB(query) {
var dbenv = config.env.configFile
var connection="";
if(dbenv=="qa"){
connection = mysql.createConnection(db.qa)
}
else if(dbenv=="stg"){
connection = mysql.createConnection(db.stg)
}
else if(dbenv=="stg2"){
connection = mysql.createConnection(db.stg2)
}
connection.connect()
return new Promise((resolve, reject) => {
connection.query(query, (error, results) => {
if (error) {
return reject(error)
}
connection.end()
return resolve(results)
})
})
}
on('task', {
'createMSSQLConnection'(query) {
return mssqlDB(query)
}
});
async function mssqlDB(query){
const connection = await mssql.connect(db.env);
var sqlServerRequest = new mssql.Request(connection);
return new Promise((resolve, reject) => {
sqlServerRequest.query(query, (error, recordset) => {
mssql.close();
if(error){
reject (error)
}
else{
resolve (recordset)
}
})
})
};
allureWriter(on, config);
const file = config.env.configFile || 'stg2';
const pathToConfigFile = path.resolve('cypress/config', `${file}.json`);
return config,fs.readJson(pathToConfigFile);
}
support/index.ts
import './commands';
import '@shelex/cypress-allure-plugin/reporter';
import 'cypress-xpath';
import 'cypress-plugin-tab';
Cypress.on('uncaught:exception', (err, runnable) => {
cy.log(`Uncaught Exception: ${JSON.stringify(err)}`);
return false;
});
I have tried many things like cleaning the cache, analyzing the index.js file but the below one fixed issue.
Uninstall the Cypress from the machine and installed with the Cypress version 8.5.0 and everything started to work fine
npm install cypress@8.5.0