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

325
Views
SyntaxError: Cannot use import statement outside a module, I have tried everything

I receive this error message when I use the import statement, it happened first when I tried to use the data-fns library which I used in the past without any issue and now I'm trying to import a class from a file to another and I receive the same error. I already tried to add "type": "module in package.json and I have tried to add type="module" in the first exercise, in the second one I'm not even using HTML at the moment, anyone knows what could be the reason? maybe I installed something globally that is causing this problem? Edit: pics when I try to use jest

ShipFactory.js

class Ship {
    constructor(length) {
    this.length = length;
  this.ships = new Array(length);
  this.sunk = false;
  }
  
  hit(num) {
    ships[num] = true;
  }

  isSunk() {
    if (this.ships.every(true)) return true
  }
}

export default Ship;

ship.test.js

import Ship from '../shipFactory.js';

describe('ship', () => {

  beforeEach(() => {
  let ship = new Ship(5)
})

test('create ship', () => {
  expect(ship).toBe({length: 5})
  })
})

package.json

{
  "name": "battleship",
  "type": "module",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "",
 "license": "ISC"
}

This is happening when I tried to use jest but it happened with the date-fns library as well

about 4 years ago · Juan Pablo Isaza
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!