Reputation: 11304
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:
node .\app.js
C:\Users\user01\scraping02\node_modules\axios\index.js:1
import axios from './lib/axios.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
My app.js:
const axios = require("axios").default;
console.log("Test");
Axios version: "1.1.3". Node version: v12.14.0.
Any hints?
Thx
Upvotes: 0
Views: 3454
Reputation: 944556
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.
Upvotes: 1