Failure to report line of error
while testing to see if node-chakra supported ES6 modules, found a difference in errors.
Of course it would be better if there weren't an error.
Reported first to Microsoft/Node; they said I should make a error here since apparently the error text comes from the engine. https://github.com/Microsoft/node/issues/15#issuecomment-174741458 and they've already made a work around to bypass unit tests that fail for similar reason.
Sample Code...
//------ main.js ------
import * as lib from 'lib';
console.log(lib.square(11)); // 121
console.log(lib.diag(4, 3)); // 5
//------ lib.js ------
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
//------ main.js ------
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
Output
M:\javascript\module-test>"H:\dev2\nodejs (chakracore)\node" main.js
SyntaxError: Syntax error
at tryWrapper (module.js:31:5)
at Module.prototype._compile (module.js:397:3)
at Module._extensions[.js] (module.js:432:3)
at Module.prototype.load (module.js:367:3)
at Module._load (module.js:324:5)
at Module.runMain (module.js:457:3)
at startup (node.js:139:11)
at Anonymous function (node.js:1001:3)
Not very informative error; nodeJS with V8 Usually outputs the source line in question... as in
NodeJS (V8)
M:\javascript\module-test>h:\dev2\nodejs\node main.js
M:\javascript\module-test\main.js:2
import * as lib from 'lib';
^^^^^^
SyntaxError: Unexpected token import
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:18)
at node.js:1003:3
@akroshg @ianwjhalliday, we should be able to pass along language service info here fairly easily, right? As long as it's a parse time error we should have detailed enough information.
I don't know how the chakra-shim for node handles printing errors and stack traces. This might just be a hosting API issue.
@kunalspathak do you know if we can improve this easily?
Even chakra-shim doesn't handle this correctly and it was reported earlier in https://github.com/Microsoft/node/issues/15#issuecomment-174741458 and I suggested to open issue here. I think the JavascriptExceptionObject need to be populated with source information and that has to come from engine.
+1
@MSLaguana IIRC you did some work have more information on exception, does that solve this issue? //cc @kfarnung @dilijev
We have since updated node-chakracore to more closely match the v8 error output:
E:\node-chakracore\main.js:1
(function (exports, require, module, __filename, __dirname) { import { square, diag } from 'lib';
^^^^^^^
SyntaxError: Module import or export statement unexpected here
<stack goes here>
Thanks @MSLaguana, closing this issue.