Running Test in Azure failed at Cypress: "The plugins file is missing or invalid"

17 views Asked by At

I'm quite a novice to React and TypeScripting. I'm creating my first Build Pipeline in Azure for a React app. It is for now just a dummy app, to make sure the build can be completed.

But it is failing at the Cypress task with the following general error:

    The plugins file is missing or invalid. 
...  

I have tried to figure out where and why it is failing at, but knowledge (or more exactly the lack of it) does not help in figuring out where the issue is hidden.

Here is the cypress/plugins/index.js

const { credentialsPlugin } = require("@mycomp/cypress/dist/plugins");

/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
 * @type {Cypress.PluginConfig}
 */
module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  return credentialsPlugin(on, config);
};

package.json

{
  "name": "management-portal",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@mycomp/analytics": "^2.0.1",
    "@mycomp/antd": "^6.6.0",
    "@mycomp/auth": "^4.0.10",
    "@mycomp/authenticated-fetch": "^1.14.0",
    "@mycomp/cypress": "^2.5.3",
    "@mycomp/get-environment": "^2.1.0",
    "@mycomp/hub-dev-server": "^2.11.3",
    "@mycomp/layout": "^3.0.6",
    "@mycomp/redirect-to-shell": "^1.1.0",
    "@mycomp/set-title": "^1.0.1",
    "@mycomp/style-tokens": "^3.21.0",
    "@sentry/react": "^5.30.0",
    "@sentry/tracing": "^5.30.0",
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "@types/jest": "^26.0.24",
    "@types/node": "^12.20.55",
    "@types/react": "^16.14.59",
    "@types/react-devtools": "^3.6.2",
    "@types/react-dom": "^16.9.24",
    "@types/react-router-dom": "^5.3.3",
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "@typescript-eslint/typescript-estree": "^4.33.0",
    "core-js": "^3.36.1",
    "cypress": "^5.6.0",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^6.15.0",
    "eslint-plugin-cypress": "^2.15.1",
    "eslint-plugin-react": "^7.34.1",
    "eslint-plugin-react-hooks": "^4.6.0",
    "jest-junit": "^11.1.0",
    "node-sass": "^4.14.1",
    "prettier": "^2.8.8",
    "prop-types": "^15.8.1",
    "raf": "^3.4.1",
    "react": "^16.14.0",
    "react-devtools": "^4.28.5",
    "react-dom": "^16.14.0",
    "react-ga": "^3.3.1",
    "react-intl": "^5.25.1",
    "react-router-dom": "^5.3.4",
    "react-scripts": "^3.4.4",
    "start-server-and-test": "^1.15.4",
    "typescript": "^4.9.5",
    "webpack": "^4.47.0",
    "whatwg-fetch": "^3.6.20"
  },
  "scripts": {
    "start": "dev-server -d start:react",
    "build": "react-scripts build",
    "test": "npm run test:unit && npm run test:e2e",
    "eject": "react-scripts eject",
    "cy:open": "cypress open",
    "cy:run": "cypress run",
    "dev": "dev-server -d start:react -s react-devtools",
    "start:react": "react-scripts start",
    "test:e2e": "start-server-and-test start http-get://localhost:3000/TODO_APP_NAME cy:run",
    "test:unit": "react-scripts test --reporters=default --reporters=jest-junit"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    "last 2 versions",
    "> 1%",
    "not dead"
  ],
  "homepage": "/ManagementPortal"
}

Here is the error:

> [email protected] cy:run /home/vsts/work/1/s
> cypress run

It looks like this is your first time using Cypress: 5.6.0

25l[22:04:36]  Verifying Cypress can run /home/vsts/.cache/Cypress/5.6.0/Cypress [started]
[22:04:38]  Verifying Cypress can run /home/vsts/.cache/Cypress/5.6.0/Cypress [completed]
25h
Opening Cypress...
The plugins file is missing or invalid.

Your `pluginsFile` is set to `/home/vsts/work/1/s/cypress/plugins/index.js`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js`, `.ts`, or `.coffee` file.

Or you might have renamed the extension of your `pluginsFile`. If that's the case, restart the test runner.

Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.

 Error: Cannot find module 'node:os'
Require stack:
- /home/vsts/work/1/s/node_modules/@azure/logger/dist/commonjs/log.js
- /home/vsts/work/1/s/node_modules/@azure/logger/dist/commonjs/debug.js
- /home/vsts/work/1/s/node_modules/@azure/logger/dist/commonjs/index.js
- /home/vsts/work/1/s/node_modules/@azure/identity/dist/index.js
- /home/vsts/work/1/s/node_modules/@mycomp/cypress/dist/plugins/azure.js
- /home/vsts/work/1/s/node_modules/@mycomp/cypress/dist/plugins/index.js
- /home/vsts/work/1/s/cypress/plugins/index.js
- /home/vsts/.cache/Cypress/5.6.0/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js
- /home/vsts/.cache/Cypress/5.6.0/Cypress/resources/app/packages/server/lib/plugins/child/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:961:15)
    at Function.Module._resolveFilename (/home/vsts/.cache/Cypress/5.6.0/Cypress/resources/app/packages/server/node_modules/tsconfig-paths/lib/register.js:75:40)
    at Module._load (internal/modules/cjs/loader.js:844:27)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/home/vsts/work/1/s/node_modules/@azure/logger/src/log.ts:4:1)
    at Module._compile (internal/modules/cjs/loader.js:1145:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
    at Object.require.extensions.<computed> [as .js] (/home/vsts/.cache/Cypress/5.6.0/Cypress/resources/app/packages/server/node_modules/ts-node/src/index.ts:529:44)
    at Module.load (internal/modules/cjs/loader.js:981:32)
    at Module._load (internal/modules/cjs/loader.js:881:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/home/vsts/work/1/s/node_modules/@azure/logger/src/debug.ts:4:1)
25hnpm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] cy:run: `cypress run`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] cy:run script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

The location of the index.js looks correct, and the file is there.

0

There are 0 answers