Skip to content

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/stack-trace/index.js from index.js not supported. #54

@soknifedev

Description

@soknifedev

Error

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/stack-trace/index.js from index.js not supported.
Instead change the require of index.js in index.js to a dynamic import() which is available in all CommonJS modules.

Code to reproduce:

index.js

import { parse } from 'stack-trace';
const err = new Error('something went wrong');
const trace = parse(err);
console.log(trace)

Environment

NodeJS 16

package.json

{
    "@babel/cli": "^7.11.6",
    "@babel/core": "^7.11.6",
    "@babel/node": "^7.10.5",
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "@babel/plugin-proposal-optional-chaining": "^7.11.0",
    "@babel/plugin-proposal-private-methods": "^7.10.4",
    "@babel/plugin-syntax-dynamic-import": "^7.8.3",
    "@babel/preset-env": "^7.11.5"
}

.babelrc

{
  "plugins": [
    "@babel/plugin-proposal-private-methods",
    "@babel/plugin-proposal-optional-chaining",
    "@babel/plugin-proposal-class-properties"
  ],
  "ignore": [],
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "16"
        }
      }
    ]
  ]
}

Hypothesis

Babel is transpiling the index.js file changing the import() statements to require() which conflicts with this module, causing the ERR_REQUIRE_ESM error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions