0

For example, if I just run the following:

node opal.min.js

The result is: /home/benjamin/workspace/1/opal.min.js:1 klass){return obj.toString()}else{return obj.$inspect()}})}(self)})(Opal);(fun ^ ReferenceError: Opal is not defined at Object.<anonymous> (/home/benjamin/workspace/1/opal.min.js:1:15264) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3

However, if I load opal in a page in Chrome and compile a "hello world" script, it runs just fine with no complaint. I can't figure out why this is happening. I'd really like to be able to run these scripts using Node.

B Seven
  • 44,484
  • 66
  • 240
  • 385
Ten Bitcomb
  • 2,316
  • 1
  • 25
  • 39

1 Answers1

0

Opal v0.7 has been released with explicit Node.js support.

In fact Node.js is the default runner for the CLI and there's a nodejs file in stdlib that will add a (basic) platform specific implementation of File, Dir, IO, etc. E.g.:

$ opal -rnodejs -e 'exit 127'
$ echo $?
127
Elia Schito
  • 989
  • 7
  • 18
  • Your example does not work. ```$ opal -rnodejs -e 'exit 127' module.js:340 throw err; ^ Error: Cannot find module 'glob' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at Function.require [as node_require] (module.js:380:17) at OpalClass.$node_require (/tmp/opal-nodejs-runner-20150209-17507-pm733y:12901:23) at /tmp/opal-nodejs-runner-20150209-17507-pm733y:13078:26 at Opal.modules.nodejs/dir (/tmp/opal-nodejs-runner-20150209-17507-... ``` – Ten Bitcomb Feb 09 '15 at 21:41
  • This is using the latest version of opal. (Opal v0.7.0) – Ten Bitcomb Feb 09 '15 at 21:42
  • yeah sorry you need to install `npm install -g glob` – Elia Schito Feb 11 '15 at 17:12
  • That sounds like it would work, but it didn't. I'm still getting the same error. ```opal -v``` ```Opal v0.7.0``` – Ten Bitcomb Feb 11 '15 at 17:16
  • Core team bias, was working on my machine because I ran it from the opal project dir which happens to contain a `node_modules` dir with `glob` installed. Need to dig deeper. – Elia Schito Feb 13 '15 at 11:53
  • Ok, in next release the node_modules dir will be shipped in the gem and I'll try to respect local and global node_modules dirs as well (that depends on how that works on node). – Elia Schito Feb 13 '15 at 12:21
  • In the meanwhile this works (after installing `glob`): `opal -rnodejs -ce 'exit 127' | node; echo $?` – Elia Schito Feb 13 '15 at 12:22
  • I've installed glob. The same problem continues to occur. I have even tried this on separate computers. – Ten Bitcomb Feb 17 '15 at 06:37
  • Forward some months, now 0.8.1 is out and works properly (just tested in a clean docker container: https://gist.github.com/elia/868754d0e4891005d5ef) no need to install `glob` anymore. – Elia Schito Oct 14 '15 at 08:12