replit / prybar

Pry open those interpreters.
GNU General Public License v2.0
253 stars 52 forks source link

Add module-context-hook ESM support #89

Closed alex-4ed5ec60d closed 2 years ago

alex-4ed5ec60d commented 2 years ago

Running an ESM Node.js repl will result in the following error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/AbleMulticoloredAstrophysics/index.mjs not supported.
Instead change the require of /home/runner/AbleMulticoloredAstrophysics/index.mjs to a dynamic import() which is available in all CommonJS modules.
    at runModule (/nix/store/9ackq82lagfpsm625fa87k32fsf5gyk2-prybar-nodejs-0.0.0-74f34a6/prybar_assets/nodejs/module-context-hook.js:196:3)
    at Object.<anonymous> (/tmp/prybar-nodejs-141666799.js:200:5)

Test plan:

  1. Write import { F_OK } from "fs"; console.log(F_OK); to index.js.
  2. It should work and print 0.
replbot commented 2 years ago

Good work, this PRs short and easy to review! Promoting to bop.

replbot commented 2 years ago

unbooping: changes requested. Make sure to address everyone's comments and dismiss any reviews before booping.

alex-4ed5ec60d commented 2 years ago

@masad-frost That is dynamic import import() we are using just for the side effect.

alex-4ed5ec60d commented 2 years ago

Updated with test plan

masad-frost commented 2 years ago

Right, I'll give it a whirl. Should be easy to write a test for.