Unexpected Token "import" in Node.js
An "Unexpected Token 'import'" error in Node.js indicates that the import syntax is not supported in the current version of Node.js. To resolve this issue, follow the guidelines provided below:
Node.js Versions
Node.js 13 :
Node.js 12:
Node.js 9:
Alternatives to Import
Prior to Node.js version 13, import was not supported. Therefore, use the classic require statement to include modules:
const express = require("express");
Babel for ES6/7 Support
If you wish to use ES6/7 features in Node.js, consider using a compiler like Babel. It can transpile your code to be compatible with older versions of Node.js. Consult the Babel documentation for further details.
The above is the detailed content of Why Am I Getting an 'Unexpected Token 'import'' Error in Node.js?. For more information, please follow other related articles on the PHP Chinese website!