Loading...
Loading...
ReferenceError: require is not defined in ES module scope. This file is being treated as an ES module because it has a '.mjs' extension.You are trying to use CommonJS 'require()' inside a file that Node.js has determined is an ES Module (ESM). Node.js treats files as ESM if they end in .mjs or if the parent package.json has 'type': 'module'.
The standard way to load modules in ESM is using the import keyword.
// ❌ Old way
// const path = require('path');
// ✅ New way (ESM)
import path from 'path';If you want to keep using require(), remove 'type': 'module' from your package.json or set it to 'commonjs'.
// package.json
{
"type": "commonjs" // or just remove the line entirely
}If you absolutely must use require in an ES module (e.g., for a legacy library).
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const myLegacyLib = require('legacy-lib');