Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [ERR_REQUIRE_ESM]: require() of ES Module #66

Open
ethereal1m opened this issue Mar 7, 2023 · 5 comments
Open

Error [ERR_REQUIRE_ESM]: require() of ES Module #66

ethereal1m opened this issue Mar 7, 2023 · 5 comments

Comments

@ethereal1m
Copy link

When executing:
const inspector = new Inspector(1, provider);

I got error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/myhome/Documents/ethereum/solidity/searcher/node_modules/mev-inspect/lib/index.js from /home/myhome/Documents/ethereum/solidity/searcher/index.ts not supported.
Instead change the require of index.js in /home/myhome/Documents/ethereum/solidity/searcher/index.ts to a dynamic import() which is available in all CommonJS modules.

However if I add
"type": "module",

in my package.json, I got error:

ReferenceError: exports is not defined in ES module scope

I am using nvm version 0.38.0

@ethereal1m
Copy link
Author

reproduceable in 2.14 version. The following is my package.json

{
  "name": "searcher",
  "version": "1.0.0",
  "description": "searching",
  "main": "index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "ethereal",
  "license": "unlicensed",
  "dependencies": {
    "mev-inspect":"2.1.4",
    "ethers": "5.7.2"
  },
  "devDependencies": {
    "@types/node": "^18.14.2",
    "ts-node": "^10.9.1",
    "tslib": "^2.5.0",
    "typescript": "^4.9.5"
  }
}

@Destiner
Copy link
Owner

Hey! Could you please share a full example for reproduction? Also, could you please try running the examples following the instruction and see if that works?

@ethereal1m
Copy link
Author

I am running nvm v19.7.0 with package.json from above. The following is the index.ts script that broke:

import { ethers } from 'ethers';
import { Inspector } from 'mev-inspect';

const key = 'xx-xxxxWPF22xxxJIdDzbDnUxxxx-xxx';
const provider = new ethers.providers.AlchemyProvider(1, key);
const inspector = new Inspector(1, provider);

It fails at "const inspector" statement.

@Gaz0h
Copy link

Gaz0h commented May 21, 2023

BUMP having the same issue

@mehranhydary
Copy link

Was able to import the inspector in a nest js app:

// Here's how you initialize
import { type Inspector } from 'mev-inspect';

let inspector: Inspector | undefined;

async function getInspector(): Promise<Inspector> {
  if (typeof inspector !== 'undefined') return inspector;
  const mod = await (eval(`import('mev-inspect')`) as Promise<
    typeof import('mev-inspect')
  >);
  return (inspector = new mod.Inspector(1, rpcProvider));
}
// and here's how I am using it in the app:
const mevInspector = await getInspector();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants