Resolved: Axios in NodeJs, ” Cannot use import statement outside a module”

In this post, we will see how to resolve Axios in NodeJs, ” Cannot use import statement outside a module”

Question:

I’m trying to call axios from a minimal NodeJs app. I’m new to JS, so sorry for the maybe dump question …
I already checked this SO answer, which doesn’t provide a solution for my problem.
The problem, when calling node:
My app.js:
Axios version: “1.1.3”. Node version: v12.14.0.
Any hints?
Thx

Best Answer:

Upgrade Node.
I’ve tested in v12.14.0, v12.22.10, and v18.7.0.
It fails with the error you get only in the first of those.
Additionally, Node v12 passed end of life in 2019 and no longer receives security fixes.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com