0

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"
  }
}

Omar
  • 1,029
  • 2
  • 13
  • 33

0 Answers0