riyadhalnur / mongoose-softdelete

Soft delete MongoDB documents
http://riyadhalnur.github.io/mongoose-softdelete
MIT License
40 stars 9 forks source link

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

Open danielortizglobant opened 3 years ago

danielortizglobant commented 3 years ago

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"
  }
}
ericpereira commented 3 years ago

same issue

nour-karoui commented 3 years ago

same issue

jatin222 commented 3 years ago

Same issue

Hani-Ghazi commented 3 years ago

same issue here