llrt: TypeError: not a function
It seems that LLRT does not load well a module (like depd) which is a collection of functions like a library.
// [depd] location: node_modules/depd/index.js
var a = require('depd') // At least it is not an error.
console.log(a);
var deprecate = require('depd')('body-parser') // LLRT makes an error.
console.log(deprecate);
In LLRT:
% llrt ./src/reproduction.js
{}
TypeError: not a function
at <anonymous> (src/reproduction.js:4:17)
In Node.js:
% node ./src/reproduction.js
[Function: depd]
[Function: deprecate] {
_file: '/Users/shinya/Workspaces/hono-test/src/reproduction.js',
_ignored: false,
_namespace: 'body-parser',
_traced: false,
_warned: [Object: null prototype] {},
function: [Function: wrapfunction],
property: [Function: wrapproperty]
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 16 (5 by maintainers)
I suspect this is due to missing
assertmodule. This error:TypeError: not a functionmeans whatever you’re trying to execute is either not implemented or is undefined 😃 Try stubbing assert and see:Yes! We however have two more (https://github.com/awslabs/llrt/issues/642 and https://github.com/awslabs/llrt/issues/641) CJS related bugs. One of them we have a patch for. The other is not to complex either. Bridging CJS and MJS seamlessly is very complicated but super useful for the end users 😃
Found the issue, it was a pretty simple fix! Functions are also Objects which we exported properties of. Now we only do so for only “real” objects. Everything else gets exported as a value.
The reproduced code for cases 1 and 2 is as follows.
And if we call these as follows, we can see the difference.
Case 3 cannot be reproduced well, so I will provide reproduction code after a little more research on the actual use case.
Can you create a simple reproducable? This seems like a bug
This is SDK v1 no? Its not supported by LLRT