Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danielortizglobant opened this issue Jan 28, 2021 · 4 comments
Open

Comments

@danielortizglobant
Copy link

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
Copy link

same issue

1 similar comment
@nour-karoui
Copy link

same issue

@jatin222
Copy link

Same issue

@Hani-Ghazi
Copy link

same issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants