Why am I seeing the error “cannot use import statement outside a module”?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This error typically occurs when you’re trying to use ES6 import syntax in Node.js but Node.js is interpreting your file in “script” mode (that uses CommonJS syntax) and not as an “ES module”. Try adding “type”: “module” in your package.json file or use the .mjs extension for your file, like filename.mjs to explicitly tell Node.js to treat your file as an ES module.