Turning code into executable file error

Hello everyone,

I need help. I’m trying to make my code an executable file. I’m using MacOS.
I managed to get the file, however, when trying and executing the file, this is the message I get:

pkg/prelude/bootstrap.js:1751
      return wrapper.apply(this.exports, args);
                     ^

ReferenceError: document is not defined
    at Object.<anonymous> (/snapshot/orbit/app.js)
    at Module._compile (pkg/prelude/bootstrap.js:1751:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Function.runMain (pkg/prelude/bootstrap.js:1804:12)
    at internal/main/run_main_module.js:17:47
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]`Preformatted text`

Any idea about what I should do to solve the issue?

You’re trying to evaluate code designed (hard coded?) for use in a browser in a non-browser environment. So in the code is at least one reference to document. That only exists when the code runs in a browser, so outside of that you’re trying to evaluate document.doSomething(), which is undefined.doSomething(), which blows up.

Without more information, can’t really advise much beyond “you possibly can’t do what you’re trying to do”

Ok, but how can I change the reference to “document” if that is the problem?

or, which kind of more information would you need to give a different answer than “you possibly can’t do what you’re trying to do”?

Thank you a lot :slightly_smiling_face:

I have no idea what you’re trying to do, that’s what I mean – that’s just effectively a generic error message that says you’re trying to run browser-specific code using Node, it doesn’t help. You could possibly tell whatever it is your running that code through (which is unknown) to replace all instances of document, but if those are using browser-specific functions (like, querySelector or fetch for example), then that doesn’t help at all because again, those things don’t exist outside the browser

Ok, yes, I use a lot of getElementById and so in my document.

I am trying to build a small game for an assignment. I made it into a running website, but one of the deliverables is an executable file, which at this point I don’t know if I can have.

Yes, but what do you mean “executable file”! Execute where? How? What’s triggering the error? What are you trying to do? What code are you trying to do it with? This is what I mean! Just saying “I have a thing I’m trying to do thing with but it doesn’t work, the thing produced this generic error”: need to know what the thing is, what the thing you’re trying do and what you’re doing it with, and what triggered the error.

1 Like

If you are trying to build an installed application that works the same way that JavaScript works in a browser (with HTML), then you need to use a tool called Electron which creates a standalone Chromium instance which can execute your JavaScript and HTML.
If you want to build a command line application in JavaScript, you can do that with Node and no Electron, but you won’t have a document (and thus no HTML, etc).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.