2

A team member uses cypress alone without a package.json, IDE setup or framework and receives the following error message:

Cannot use import statement outside a module

The first part of the e2e test looks like this:

describe('Dummy', () => {
  before(() => {
    cy.visit(Cypress.env('baseURL'));
    cy.contains('Log in').click();
    cy.get('input[name="username"]').type('test user').should('have.value', 'test user');
    cy.get('input[name="password"]').type('test password').should('have.value', 'test password');
  });
});

The tests are partially running and the first two commands (visit & contains) work in the example provided.

But when it comes to the line in which a username and password must be entered, the test failed with the error message mentioned above.

I think he is trying to execute it as an ES2015 module, but node.js only understands CommonJS. There are possibilities to fix it in the package.json, but since it doesn’t use a package.json I don't know what to do.

Is there another workaround for this?

Codehan25
  • 2,704
  • 10
  • 47
  • 94

1 Answers1

-2

See this answer. These are typical things you would define in your (test) code's package.json and/or tsconfig.json (when using TypeScript). Doing this beforehand prevents all sorts of "(doesn't) work(s) on my machine" issues like the the one you just described.

david-err
  • 1,037
  • 1
  • 8
  • 12