Categories
JavaScript Answers

How to fix Node error: SyntaxError: Unexpected token import?

Spread the love

To fix Node error: SyntaxError: Unexpected token import, we can use CommonJS modules.

For instance, we write

const calc = require("./calc");
const { add, multiply } = calc;

to call require to include the calc.js module file.

And then we get the add and multiply properties from the object we set as the value of module.exports in calc.js.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *