cypress-esbuild-preprocessor icon indicating copy to clipboard operation
cypress-esbuild-preprocessor copied to clipboard

Dynamic require of is not supported when running a cypress test

Open artipsingh opened this issue 2 years ago • 0 comments

I am getting a message that Dynamic require of <> is not supported when I try to run a cypress test either from the command line or from the cypress GUI, not really sure what to do to fix this, I had been under the impression that putting the package in external: ['cypress-*'] would make esbuild ignore my package, but this does not appear to be the correct assumption.

Has anyone had this error before ?

My custom esbuild configurations in cypress/plugins/index.js

const bundler = createBundler({
      platform: 'node',
      format: 'iife',
      external: ['cypress-*'],
      packages: 'external',
  });
on('file:preprocessor', bundler);

node modules are : "@bahmutov/cypress-esbuild-preprocessor": "2.2.0", "esbuild": "0.17.19",

My error when I run a test with Cypress

The following error originated from your test code, not from Cypress.

Dynamic require of "cypress-file-upload" is not supported When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. Cypress could not associate this error to any specific test. We dynamically generated a new test to display this failure.

 at eval (https://<REDACTED>/__cypress/tests?p=cypress/support/e2e.js:27:11)
    at cypress/support/commands.js (<REDACTED>/__cypress/tests?p=cypress/support/e2e.js:40:36)
    at __init (https://<REDACTED>/__cypress/tests?p=cypress/support/e2e.js:30:58)
    at cypress/support/e2e.js (<REDACTED>/__cypress/tests?p=cypress/support/e2e.js:3453:7)
    at __require2 (https://<REDACTED>/__cypress/tests?p=cypress/support/e2e.js:33:52)
    at eval (<REDACTED>/__cypress/tests?p=cypress/support/e2e.js:3489:3)
    at eval (<REDACTED>/__cypress/tests?p=cypress/support/e2e.js:3490:3)
    at eval (<anonymous>)
From previous event:
    at evalScripts (<REDACTED>__cypress/runner/cypress_runner.js:168521:58)
    at <unknown> (<REDACTED>/__cypress/runner/cypress_runner.js:168530:152)
From previous event:
    at runScriptsFromUrls (https://<REDACTED>/__cypress/runner/cypress_runner.js:168530:136)
    at Object.runScripts (https://<REDACTED>/__cypress/runner/cypress_runner.js:168571:12)
    at $Cypress.onSpecWindow (https://<REDACTED>/__cypress/runner/cypress_runner.js:157151:75)

my cypress/support/e2e.js file

import './commands';
import 'cypress-axe';
import 'cypress-file-upload';

artipsingh avatar Jul 20 '23 20:07 artipsingh