-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiledWrapper.apply is not a function #29
Comments
I could reproduce it using VSCode debugger, only using Node 10.16.x. Node 12 works properly. However, I could not reproduce it when running your app interactively (in Node REPL). Still investigating what could be the cause. |
Could you please try this scenario with Node 12? |
The problem happens because the script created by bytenode, here: let script = new vm.Script(dummyCode, {
filename: filename,
lineOffset: 0,
displayErrors: true,
cachedData: bytecodeBuffer
}); does NOT use the if (script.cachedDataRejected) {
throw new Error('Invalid or incompatible cached data (cachedDataRejected)');
} so the flag (I tried to run After some searching and digging in v8 source code, I found nothing. But this issue nodejs/node#20052 might be related. It's mentioned in this comment nodejs/node#20052 (comment) that when providing Anyways, the problem now is clear, in Node ≤ 10: Debug mode breaks bytenode (because it uses the empty |
Thanks for your work on this. And also thanks for a great piece of software overall, I forgot to mention that!
I saw that problem for a much larger JSC file which contains a much larger quantity (~5MB) of JS. Again, it was annoyingly inconsistent so it's hard to say what the specific issue is.
With Node.js v12.10.0 I was unable to reproduce this issue. (Although, as I say, because the problem with the larger packages was inconsistent, it's hard to be sure whether it's been resolved completely.) Upgrading from Node.js v10 to v12 is a possibility for us although there are some drawbacks. In any case, we will definitely keep that in mind as a potential workaround. I think at the very least it would be good to document this problem as a known issue in the README. The Node.js issue you linked does seem to be related. It would explain all of the behaviour I'm seeing if Node is having intermittent trouble with the cached code we're providing it, but not returning the right I'm going to see if I can pull out some of the internals of |
Well, while trying to pare this down to a simpler case, I have arrived at what could be an unrelated issue where const Module = require('module')
const v8 = require('v8')
const vm = require('vm')
v8.setFlagsFromString('--no-lazy')
const bytecodeBuffer = new vm.Script(Module.wrap('console.log("hello world")')).createCachedData() works fine under normal circumstances and returns a sensible |
My initial guess was that the debug mode has some "flag hash" different than the normal mode. This difference could explain why the normal compiled jsc files can't be debugged. But then I tried to compile in the debug mode itself and nothing worked. So maybe your last comment is pointing to the other direction: the debug mode in Node ≤ 10 somehow breaks CachedData mechanism. It's now almost clear that the issue lies in v8 itself, not node internals, and of course not in bytenode. Bytenode is nothing but a very thin layer. Most of bytenode source code is straightforward, the only part that might need to be explained is how we "fix" the bytecode cache (by compiling a very small piece of code, and read its flags, then we use it to pass the sanity checks of v8: see v10.x, v11.x). The differences in this part between Node versions is related to how the data header is defined (which is inaccurate by the way in the comments, we had to read the source code to find the correct order of these bytes). That being said: we cannot fix our issue WITHOUT changing the v8 source itself. This means that we would have to compile a custom version of Node v10.x (which is against the very idea of bytenode). However, if you want to do this yourself: it's easier to disable the sanity checks alltogether. This is the approach that NW.js guys followed in their implementation of "nwjc" tool. See here. Your options now are:
In bytenode, I will edit the README file soon to mention this limitation. Thank you for your report. |
Alright, well I'm glad the problem isn't in bytenode... thanks for the additional information about how this package works internally. And thank you very much for the suggestions about chasing this problem down. I will see about raising an issue for Node and/or V8 and I'll take a look at the nwjc tool you mentioned as well. Thank you for your help. :) |
Thank you for you kind words. Sorry I could not solve it. Hope you can find a suitable workaround. |
I have solved this problem. |
use this way, when develp, the editor can show the tip normally. It is very useful |
This is Node.js v10.16.0 on Windows 10 64-bit. We also see this on Node.js v10.16.2 on Linux 64-bit.
This is a really puzzling and intermittent error and I must apologise but it's been very difficult to come up with consistent steps to reproduce it. I feel as if the problem may be environmental but there are aspects of how
bytenode
works which I do not understand so I'm not sure what kind of environmental issue could be causing this, which is why I'm reaching out for help. Here's the minimal scenario I've managed to concoct:src/main.js
:build/build.js
(this consumessrc/main.js
and outputsdist/main.jsc
):dist/main.jsc
is about 1kB of bytecode, of course, and I can't attach it, but here's the Base64 for it if that's any use:index.js
(this serves as the entry point):When I run
index.js
, I getWhen I debug
index.js
(my debugger in this case is WebStorm 2019.2), I getI also see this problem when not debugging, in some scenarios where the
bytenode
d source is much larger. In this case I find that trying to load the module interactively, e.g.causes the
compiledWrapper
error to repeat on each attempt... but simply exiting the interactive session and runningnode
again can cause the problem to go away semi-permanently.Closer inspection of
Module._extensions[.jsc]
indicates that under normal circumstances, the value returned fromcompiledWrapper = script.runInThisContext(...)
is a function, whose string representation is 91 copies of U+200B ZERO WIDTH SPACE in a row. But in the failure case,compiledWrapper
is simply a 92-character string consisting of U+200B ZERO WIDTH SPACEs. In both caseslength = readSourceHash(bytecodeBuffer)
returned 94. A string has noapply
method on it, hence the error.What could be causing this?
The text was updated successfully, but these errors were encountered: