• Home
  • Type module in package json throw new err_require_esmfilename parentpath packagejsonpath – Node JS

Type module in package json throw new err_require_esmfilename parentpath packagejsonpath – Node JS

It looks like you are trying to import an ES module using the require function, which is not supported in Node.js. The require function is used to import CommonJS modules, which are different from ES modules.

To fix this error, you can try one of the following options:

  1. Use the import statement instead of require to import an ES module.
  2. Convert the ES module to a CommonJS module by using a tool like Babel or webpack.
  3. Make sure that the file being imported is actually a CommonJS module and not an ES module.

For example, if you are trying to import a file called foo.js, you can use the following code to import it as an ES module:

import foo from './foo.js';

Or, you can use the following code to import it as a CommonJS module:

const foo = require('./foo.js');