anmonteiro / lumo

Fast, cross-platform, standalone ClojureScript environment
Eclipse Public License 1.0
1.88k stars 85 forks source link

Error: This file should not be required #423

Open lilactown opened 6 years ago

lilactown commented 6 years ago

I'm attempting to use shelljs for some command-line scripts.

Using the built-ins like cd and ls work fine. However, attempting to use exec throws this strange error:

(node:93637) UnhandledPromiseRejectionWarning: Error: This file should not be required
    at Object.<anonymous> (/Users/will/Code/textalert/ions/scripts/node_modules/shelljs/src/exec-child.js:2:9)
    at Module._compile (module.js:649:30)
    at Object.yt [as eval] ([eval]:1:33012)
    at Object.lumo.repl.caching_node_eval (<embedded>:6478:68)
    at <embedded>:6606:454
    at Object.lumo.repl.run_sync_BANG_ [as run_async_BANG_] (<embedded>:6452:108)
    at Object.cljs.js.process_deps (<embedded>:5621:185)
    at Object.cljs.js.process_libs_deps (<embedded>:5624:60)
    at <embedded>:6605:424
    at Object.lumo.repl.run_sync_BANG_ [as run_async_BANG_] (<embedded>:6452:108)
(node:93637) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:93637) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ENOENT: no such file or directory, open '/var/folders/8s/pk84jrts4w7bhywt8_kpv5080000gn/T/shelljs_57eca9433c3d6ca864ec'
     Object.fs.openSync (fs.cljs:667:18)
     Object.fs.readFileSync (fs.cljs:572:33)
     execSync (/Users/will/Code/textalert/ions/scripts/node_modules/shelljs/src/exec.cljs:89:17)
     Object._exec (/Users/will/Code/textalert/ions/scripts/node_modules/shelljs/src/exec.cljs:202:12)
     Object.exec (/Users/will/Code/textalert/ions/scripts/node_modules/shelljs/src/common.cljs:335:23)
     (evalmachine.<anonymous>:1:14)
     Script.runInThisContext (vm.cljs:65:33)
     Object.runInThisContext (vm.cljs:197:38)
     (Object.yt)
     (Object.lumo.repl.caching_node_eval)

Simple repro steps:

mkdir shelljs-repro
cd shelljs-repro
npm init -y
npm i shelljs
lumo -e '(-> (js/require "shelljs") (.exec "ls"))'

Lumo version: 1.9.0-alpha Node.js version: 8.9.1 and 10.3.0 Shelljs version: 0.8.2

hlolli commented 6 years ago

I get the same

lumo -e '(-> (js/require "shelljs") (.exec "ls"))'      

(node:9361) UnhandledPromiseRejectionWarning: Error: This file should not be required
    at Object.<anonymous> (/home/hlolli/Music/erkitid_2018/node_modules/shelljs/src/exec-child.js:2:9)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.yt [as eval] ([eval]:1:33012)
    at Object.lumo.repl.caching_node_eval (<embedded>:6477:68)
    at <embedded>:6605:454
    at Object.lumo.repl.run_sync_BANG_ [as run_async_BANG_] (<embedded>:6451:108)
    at Object.cljs.js.process_deps (<embedded>:5816:185)
    at Object.cljs.js.process_libs_deps (<embedded>:5819:60)
    at <embedded>:6604:424
    at Object.lumo.repl.run_sync_BANG_ [as run_async_BANG_] (<embedded>:6451:108)
(node:9361) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9361) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ENOENT: no such file or directory, open '/tmp/shelljs_3c357cb12430abedd941'
     Object.openSync (fs.cljs:443:3)
     Object.readFileSync (fs.cljs:348:35)
     execSync (/home/hlolli/Music/erkitid_2018/node_modules/shelljs/src/exec.cljs:89:17)
     Object._exec (/home/hlolli/Music/erkitid_2018/node_modules/shelljs/src/exec.cljs:202:12)
     Object.exec (/home/hlolli/Music/erkitid_2018/node_modules/shelljs/src/common.cljs:335:23)
     (evalmachine.<anonymous>:1:20)
     Script.runInThisContext (vm.cljs:91:20)
     Object.runInThisContext (vm.cljs:298:38)
     (Object.yt)
     (Object.lumo.repl.caching_node_eval)

On the other hand, Nodejs doesn't do it

node -e 'let shelljs = require("shelljs"); shelljs.exec("ls");'                                                                                          ~/Music/erkitid_2018
node_modules
package.json
package-lock.json
shadow-cljs.edn
src

The code that "fails" is

$ cat node_modules/shelljs/src/exec-child.js                                                                                                               

if (require.main !== module) {
  throw new Error('This file should not be required');
}
...elided...

as far as I see, the demand of this library shelljs to have .exec only be used directly from the command line (as explained here https://stackoverflow.com/questions/45136831/node-js-require-main-module ) is perhaps a no-solve for a self-hosted clojurescript. But maybe there's a way to hack lumo so that it defers the require.main setter, if doing that could be consequent free thing to do.

lilactown commented 6 years ago

🙄 I might just fork shelljs then. Seems inconsequential.

anmonteiro commented 6 years ago

probably related to #285

vesubramanian commented 3 years ago

Any update on this issue? I am also facing this issue. I am trying to use shelljs echo (to output something to a file) and exec methods to execute 'sudo update-ca-certificates'. I get an error "This file should not be required." in exec-child.js