Categories
JavaScript Answers

How to fix referenceerror: exports is not defined in ES module scope with JavaScript?

Spread the love

To fix referenceerror: exports is not defined in ES module scope with JavaScript, we should make sure we’re using export in an ES module instead of module.exports.

For instance, we write

const foo = () => {};

export { foo };

to create an ES module that exports the foo function as a named export.

We can also create a default export with

const foo = () => {};

export default foo;

to export foo as a default export.

module.exports is only used in CommonJS modules to export their members.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.