1 year ago
#383595
g_cardillo
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
javascript
import
module
syntax-error
0 Answers
Your Answer