Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
How to use libraries in a node js project

I don't know what I'm doing. I don't understand why it shows me the following errors. First of all, I want to say that I've searched for info and self explain videos but I can't solve this error. So I want to create a node js project. For that, I use npm init and set app.mjs as my script. Then, I do npm install axios and go live in a local server. I write in app.mjs the following line to follow ES6 module codetype but I get this error in the console:

import axios from 'axios'
// Error:  Uncaught SyntaxError: Cannot use import statement outside a module

I have "type": "module" in my package.json. I've tried to use require replacing.js too but it doesn't work neither.

What I'm doing wrong? Furthermore, to not having the same error, how am I supposed to do it in a corrrect way in my future projects?

EDIT: Adding package.json

{
  "name": "testproject",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "app.mjs",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.21.4",
    "cheerio": "^1.0.0-rc.10",
    "http": "^0.0.1-security"
  }
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!