-2

I am writing some Javascript code. I created a js file which contain my exports. However, when I import it into the other js file, I get an error which says SyntaxError: Cannot use import statement outside a module.

I am using WebStorm. Here is the code:

exports(math.js).

export var add=function (n1,n2) { return n1 + n2; };

export var subtract=function (n1,n2) { return n1 - n2; };

export var multiply=function (n1,n2) { return n1 * n2; };

export var divide=function (n1,n2) { return n1 / n2; };


import import * as math from './math';

console.log(math.add(2,2)); console.log(math.subtract(2,2)); console.log(math.multiply(2,2)); console.log(math.divide(2,2));
skomisa
  • 16,436
  • 7
  • 61
  • 102
Doe
  • 47
  • 6

1 Answers1

0

use require instead of import

const someImported =require('fileName.js')
Alwani Anis
  • 260
  • 3
  • 11