Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda