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

Warning: require() of ES modules is not supported. #52

Closed
xeroxstar opened this issue Jul 30, 2020 · 1 comment
Closed

Warning: require() of ES modules is not supported. #52

xeroxstar opened this issue Jul 30, 2020 · 1 comment

Comments

@xeroxstar
Copy link

Hello,
For some reason i am starting getting this error, this module used to work fine but now i am not able to work with it... Is there a fix?

let observ = require('./object-observer/dist/node/object-observer');
Warning: require() of ES modules is not supported.
require() of C:\Users\user\Desktop\avrorajs\bin\object-observer\dist\node\object-observer.js from C:\Users\user\Desktop\project\bin\bundle.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 object-observer.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\user\Desktop\project\bin\object-observer\package.json.
@xeroxstar
Copy link
Author

xeroxstar commented Jul 30, 2020

Found the solution here "Warning: require() of ES modules is not supported", adding the code solved the problem:

const module = require('module');
const fs = require('fs');
module.Module._extensions['.js'] = function (module, filename) {
  const contents = fs.readFileSync(filename, 'utf8');
  module._compile(require('fs').readFileSync(filename, 'utf8'), filename);
};

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

1 participant