Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

327
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda