Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

372
Views
Cypress: Cannot use import statement outside a module

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!