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

ERR_REQUIRE_ESM on running project #12

Closed
subhasisghosal opened this issue Oct 26, 2020 · 3 comments
Closed

ERR_REQUIRE_ESM on running project #12

subhasisghosal opened this issue Oct 26, 2020 · 3 comments

Comments

@subhasisghosal
Copy link

I have imported the package as instructed as follows:
const softDelete = require('mongoose-softdelete');
But whenever I'm running the project, I'm facing an error like below:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/subhasis/Work/mpac-dispenser/node_modules/mongoose-softdelete/src/mongoose-softdelete.js require() of ES modules is not supported. require() of /home/subhasis/Work/mpac-dispenser/node_modules/mongoose-softdelete/src/mongoose-softdelete.js from /home/subhasis/Work/mpac-dispenser/models/medicine.js 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/subhasis/Work/mpac-dispenser/node_modules/mongoose-softdelete/package.json.
Kindly fix this issue otherwise give a solution to overcome this. If I comment out the require line then it runs fine.

@riyadhalnur
Copy link
Owner

The documentation needs to be updated for the JS example. You can go ahead and use import to use this package if you're using the latest version of NodeJS

@subhasisghosal
Copy link
Author

subhasisghosal commented Nov 4, 2020

I'm using the latest version of node. But I'm using require for all other imports. So if I use import statement only for this package then it gives me the following error:
SyntaxError: Cannot use import statement outside a module
@riyadhalnur kindly help regarding this

@riyadhalnur
Copy link
Owner

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

2 participants