replit / prybar

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

prybar-nodejs fails with ES Modules #83

Open sflanker opened 2 years ago

sflanker commented 2 years ago

In Node.js 16+ it is possible to have a package entry point be an ECMA Script module. However when you try to run prybar-nodejs -i index.js with such a package it fails to load the specified file with the following error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
    at new NodeError (node:internal/errors:371:5)
    at validateString (node:internal/validators:119:11)
    at Object.basename (node:path:1309:5)
    at Error.<anonymous> (node:internal/errors:1459:55)
    at getMessage (node:internal/errors:421:12)
    at new NodeError (node:internal/errors:348:21)
    at Module._extensions..js (node:internal/modules/cjs/loader:1128:19)

If I change the filename to index.mjs I get the following:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/Node16Repl/index.mjs not supported.
Instead change the require of /home/runner/Node16Repl/index.mjs to a dynamic import() which is available in all CommonJS modules.
    at runModule (/nix/store/af4zlyjyr5wajad3k1kyrj2abrqra7xl-prybar-nodejs-0.0.0-a584d8e/prybar_assets/nodejs/module-context-hook.js:191:3)
    at Object.<anonymous> (/tmp/prybar-nodejs-349568109.js:200:5)
sflanker commented 2 years ago

As a workaround the following can be used in .replit:

[interpreter]
command = [ "prybar-nodejs", "-i", "-ps1", "\u001b[33m\uEEA7\u001b[00m ", "-c", "import('./index.js')"]

The straight command line looks like: prybar-nodejs -i -c "import('./index.js')"

superboss224 commented 2 years ago

Using that command in .replit loop-runs the code on errors, or on process.exit(), and you can't stop a script running easily

Is there a way to improve that command so it executes more smoothly ?