Skip to content

ReferenceError: require is not defined – JavaScript

Error message:

file.js:1 uncaught referenceerror: require is not defined

Browser-based

require() does not exist within the browser javascript. Use import defaultExport from "module-name" or import { export1 } from "module-name";

Node.js

require() can only be used if the module.exports syntax is used, removed "type":"module" from the package.json and rename any files with the .mjs extension to .js.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.