mongoose-softdelete icon indicating copy to clipboard operation
mongoose-softdelete copied to clipboard

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

Open danielortizglobant opened this issue 3 years ago • 4 comments

Hi im trying to use soft delete with typescript


Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/globant/Documents/repos/spybee/node_modules/mongoose-softdelete/src/mongoose-softdelete.js
require() of ES modules is not supported.
require() of /home/globant/Documents/repos/spybee/node_modules/mongoose-softdelete/src/mongoose-softdelete.js from /home/globant/Documents/repos/spybee/src/models/user.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename mongoose-softdelete.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/globant/Documents/repos/spybee/node_modules/mongoose-softdelete/package.json.



Package.json


{
  "name": "spybee",
  "version": "1.0.0",
  "description": "Spybee backend",
  "main": "app.js",
  "scripts": {
    "clean": "rm -r -f ./build",
    "tsc": "tsc",
    "test": "echo \"Error: no test specified\" && exit 1",
    "start:dev": "nodemon",
    "start:local": "ts-node ./src/server.ts",
    "build": "tsc -p tsconfig.json",
    "add-develop": "git remote add develop https://git.heroku.com/spybee-api.git",
    "push-develop": "git push develop develop:master",
    "start": "node ./build/src/server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@sendgrid/mail": "^7.4.2",
    "@types/bcrypt": "^3.0.0",
    "@types/cors": "^2.8.9",
    "@types/express": "^4.17.11",
    "@types/mongoose": "^5.10.3",
    "bcrypt": "^5.0.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "eslint": "^5.15.3",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-jest": "^22.3.0",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-simple-import-sort": "^4.0.0",
    "express": "^4.17.1",
    "joi": "^17.3.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.11.12",
    "mongoose-softdelete": "^1.2.0",
    "nodemon": "^2.0.7",
    "ts-node": "^8.0.3",
    "typescript": "^4.1.3"
  },
  "devDependencies": {
    "@types/jsonwebtoken": "^8.5.0",
    "@typescript-eslint/eslint-plugin": "^1.4.2",
    "@typescript-eslint/parser": "^1.4.2"
  }
}

danielortizglobant avatar Jan 28 '21 02:01 danielortizglobant

same issue

ericpereira avatar Apr 25 '21 20:04 ericpereira

same issue

nour-karoui avatar Apr 26 '21 09:04 nour-karoui

Same issue

jatin222 avatar Jun 17 '21 10:06 jatin222

same issue here

Hani-Ghazi avatar Jul 06 '21 08:07 Hani-Ghazi