Broken console from require’d module

#1

console acts as usual in index.js, but in require‘d modules, console.log will not output anything, and the console‘s from inside and outside differ:

Example 1:

// index.js
console.log(require('./test.js')); // This will output
// test.js
console.log(module.exports = 'test'); // But this won’t

Example 2:

// index.js
console.log(require('./test.js') === console); // Prints false instead of true
// test.js
module.exports = console;
0 Likes

#2

Hi rikumi :wave:

This is a known issue due to some limitations of the Node.js runtime port, we’re still investigating but we’ll come back to you with any updates as soon as possible.

Thank you.

0 Likes

#3

Seems that the scripts are executed from a repl-like environment. I think there might be some hack to get them to ‘really run by themselves,’ which should prevent much more related issues.

1 Like

#4

You’re guessing right rikumi. Take into account that iOS sandboxing doesn’t let apps launch child processes therefore every node program is run in the same process. This means that in order to control things like the script execution, stdin, stdout, etc we have to use a repl like environment.

play.js already tweaks some aspects of the Node.js port we use (ChakraCore) to achieve an experience as close as possible to the real thing. Sharing contexts with modules in the same repl session is in the backlog :slight_smile:.

1 Like

#5

play.js 1.8.1 has been submitted for review including a fix for this issue. The build should be available in 1~2 days :slightly_smiling_face:

0 Likes