After running npm run dev, I get the following errors:
> [email protected] dev
> nodemon index.js --exec babel-node
[nodemon] 1.18.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node index.js`
(node:20560) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\Users\elvis\Documents\Proyecto Express\sistema\index.js:1
import express from 'express'; //const express=require('express');
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:984:16)
at Module._compile (internal/modules/cjs/loader.js:1032:27)
at Module._compile (C:\Users\elvis\AppData\Roaming\npm\node_modules\@babel\node\node_modules\pirates\lib\index.js:136:24)
at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Object.newLoader [as .js] (C:\Users\elvis\AppData\Roaming\npm\node_modules\@babel\node\node_modules\pirates\lib\index.js:141:7)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at Object.<anonymous> (C:\Users\elvis\AppData\Roaming\npm\node_modules\@babel\node\lib\_babel-node.js:176:21)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
[nodemon] app crashed - waiting for file changes before starting...
I have tried all the possible solutions:
This is my package.json file:
{
"name": "sistema",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js --exec babel-node"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-3": "^6.24.1",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"express": "^4.16.4",
"express-promise-router": "^3.0.3",
"jsonwebtoken": "^8.5.0",
"mongoose": "^5.4.10",
"morgan": "^1.9.1"
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}
And this is my .babelrc file:
{
"presets": [
//"env" ,
//"stage-3"
]
}
Is someone able to provide me some help or suggestions?
Thank you,
I solved this issue by installing babel with npm install babel-cli babel-core --save-dev