Hello!
I´m doing a rote to search but it´isnt work
index.js
tasks.js
I´m doing a rote to search but it´isnt work
Code:
C:\Users\arifu\ntask-api\node_modules\consign\lib\consign.js:121
^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\ar\ntask-api\models\tasks.js from C:\Users\ar\ntask-api\node_modules\consign\lib\consign.js not supported.
tasks.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename tasks.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Users\ar\ntask-api\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at Object.newLoader [as .js] (C:\Users\ar\ntask-api\node_modules\pirates\lib\index.js:121:7)
at Consign.into (C:\Users\ar\ntask-api\node_modules\consign\lib\consign.js:232:15)
at file:///C:/Users/ar/ntask-api/index.js:14:3 {
code: 'ERR_REQUIRE_ESM'
}
JSON:
{
"name": "ntask-api",
"version": "1.0.0",
"description": "API de gestão de tarefas",
"main": "index.js",
"type": "module",
"scripts": {
"start": "babel-node index.js"
},
"author": "Maria Izabel",
"dependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"consign": "^0.1.6",
"express": "^4.18.2"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/node": "^7.0.0",
"@babel/preset-env": "^7.23.3"
}
}
index.js
JavaScript:
import express from 'express';
import consign from 'consign';
const app = express();
app.set("json spaces", 4)
consign()
.include("models")
.then("libs/middlewares.js")
.then("routes")
.then("libs/boot.js")
.into(app);
tasks.js
JavaScript:
module.exports = app => {
return{
findAll:(params, callback) =>{
return callback([
{title: "Fazer Compras"},
{title: "Consertar o pc"},
]);
}
};
};
Last edited by a moderator: