Duktape を使用して JavaScript を埋め込んでいますが、使用するrequire
と常にエラーが発生します。
int main(){
duk_context *ctx = duk_create_heap_default();
duk_peval_file(ctx, "example.js");
printf("file load err %s", duk_safe_to_string(ctx, -1));
duk_destroy_heap(ctx);
}
example.js
var mylib = require("mylib")
print (mylib.hello)
mylib.js
exports.hello = "Hello"
エラー:
ファイル読み込みエラー TypeError: 呼び出し可能ではありません
スタック ダンプは次のように述べています。
duk_js_call.c:682
require native strict preventyield
eval example.js:1 preventyield