Open
Description
I'm trying to run Cypress tests on Browserstack, but keep getting this. I'm on Cypress 13.6.4 and [email protected]
Not sure how to fix this ESM/CJS issue. Here's my cypress.config.ts
import task from "@cypress/code-coverage/task";
import { allureCypress } from "allure-cypress/reporter";
import { defineConfig } from "cypress";
import cypressSplit from "cypress-split";
export default defineConfig({
e2e: {
specPattern: "cypress/e2e/**",
supportFile: "cypress/support/index.js",
projectId: "test",
video: true,
chromeWebSecurity: false,
reporter: "cypress-multi-reporters",
screenshotsFolder: "./cypress/report/mochawesome-report/assets/screenshots",
reporterOptions: {
configFile: "reporter-config.json"
},
numTestsKeptInMemory: 0,
retries: {
runMode: 1,
openMode: 0
},
viewportWidth: 1920,
viewportHeight: 1920,
defaultCommandTimeout: 40000,
requestTimeout: 30000,
pageLoadTimeout: 40000,
setupNodeEvents(on, config) {
task(on, config);
cypressSplit(on, config);
// allureWriter(on, config);
allureCypress(on, {
resultsDir: "./allure-results"});
on("before:browser:launch", (browser, launchOptions) => {
launchOptions.args.push("--another-arg");
if (browser.family === "chromium" && browser.name !== "electron") {
launchOptions.args.push("--disable-dev-shm-usage");
}
return launchOptions;
});
return config;
}
}
});
/Users/pcanella/.nvm/versions/node/v18.19.0/lib/node_modules/browserstack-cypress-cli/bin/helpers/requireModule.js:7
const mod = require(moduleName)
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/pcanella/gitrepo/feecalculatorfe/tmpBstackCompiledJs/cypress.config.js from /Users/pcanella/.nvm/versions/node/v18.19.0/lib/node_modules/browserstack-cypress-cli/bin/helpers/requireModule.js not supported.
cypress.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename cypress.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/pcanella/gitrepo/feecalculatorfe/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at Object.<anonymous> (/Users/pcanella/.nvm/versions/node/v18.19.0/lib/node_modules/browserstack-cypress-cli/bin/helpers/requireModule.js:7:13) {
code: 'ERR_REQUIRE_ESM'
}
Metadata
Metadata
Assignees
Labels
No labels