Axios in NodeJs, " Cannot use import statement outside a module"

Moerwald

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

Quentin

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

SyntaxError: Cannot use import statement outside a module { AXIOS }

Jest - SyntaxError: Cannot use import statement outside a module with @nestjs/axios

NodeJs project SyntaxError: Cannot use import statement outside a module

NodeJS --> SyntaxError: Cannot use import statement outside a module

Issues compiling nodejs code with ts-node (Cannot use import statement outside a module)

NodeJS: Cannot use import statement outside a module(already tried type :"module")

Unsure how to fix "SyntaxError: Cannot use import statement outside module" error in nodejs/expressjs even using "type": "module"

SyntaxError: Cannot use import statement outside a module

cannot use import statement outside a module error

Serviceworker and cannot use import statement outside a module

Cannot use import statement outside a module @emotion

SyntaxError: Cannot use import statement outside of module

Cannot use import statement outside a module in laravel project

Error on Heroku: `SyntaxError: Cannot use import statement outside a module`

How to fix "SyntaxError: Cannot use import statement outside a module"

Using TypeScript and nodemon: SyntaxError: Cannot use import statement outside a module

Javascript Module error SyntaxError: Cannot use import statement outside a module

TypeORM Entity in NESTJS - Cannot use import statement outside a module

Cannot use import statement outside a module when I import a module

Mocha + TypeScript: Cannot use import statement outside a module

Node.js: SyntaxError: Cannot use import statement outside a module

Uncaught SyntaxError: Cannot use import statement outside a module

SyntaxError: Cannot use import statement outside a module - jsfiddle

Jest - SyntaxError: Cannot use import statement outside a module

Javascript Modules SyntaxError: Cannot use import statement outside a module

cannot use import statement outside a module with Next.js

Cannot use import statement outside a module in Vuejs. Template Django

Uncaught SyntaxError: Cannot use import statement outside a module in node js

jQuery in wordpress showing warning of 'cannot use import statement outside a module