Compiling a standalone executable using modern JavaScript/TypeScript runtimes #8096
guest271314
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Source: https://gist.github.com/guest271314/9b1adad3db3deba64e118f844a77bad6
Compiling a standalone executable using modern JavaScript/TypeScript runtimes
We have the same code working using
node
,deno
, andbun
.E.g.,
which each produce a Signed Web Bundle and that is an Isolated Web App.
We have a
node_modules
folder thatnode
,deno
andbun
each utilize formodule source.
For
deno
we pass--unstable-byonm
flag to use thenode_modules
folder.
For
node
we use the--experimental-default-type=module
flag to use Ecmascriptmodules with
.js
extension.OS: Linux x86.
References:
That's it. Let's see how simple or complicated it is to compile a JavaScript
application to a single executable containing your source code and the given
JavaScript runtime.
What does
bun
have to say on the first run?bun build --compile
works on first run.Let's try Deno next.
Why would
deno
, a TypeScript runtime neednpm:@types/node
?Whatever, alright, we'll install
npm:@types/node
.Let's try Deno again, and make sure
--output=deno_exe
is not expected to beindex.js
Alright! Deno created the self-contained executable!
Let's run the output executable file
Foiled again.
My estimation is that the error has to do with an entry in
package.json
ispointing to a
.git
extension on GitHub. I have not confirmed that is the case, yet.Next up, Node.js.
There's a bit to unpack and re-read in the Node.js version. Some key points which
essentially prevent us from proceeding as-is
I'm using Ecmascript Modules, not CommonJS. We should try anyway.
Results:
bun
sucessfully compiled the standalone executable.deno
compiled the standalong executable, after installing@types/node
(whichalso installs
undici-types
), however, the standalone executable throws and error.node
only supports CommonJS. We tried anyway where we know the source isEcmascript Modules.
bun x
equivalent ofnpx postject hello NODE_SEA_BLOB sea-prep.blob \ --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
per the Node.js Single Executable Application documentation throws an error.These are the empirical results I'm sharing experimenting and testing compiling
a standalone executable that achieves the same result when run
in the given JavaScript runtime using the same source code.
Beta Was this translation helpful? Give feedback.
All reactions