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.