Skip to content
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

make deno installable in stackblitz #26894

Open
mfulton26 opened this issue Nov 16, 2024 · 3 comments
Open

make deno installable in stackblitz #26894

mfulton26 opened this issue Nov 16, 2024 · 3 comments
Labels
suggestion suggestions for new features (yet to be agreed)

Comments

@mfulton26
Copy link

Attempting to install Deno inside a Stackblitz Web Container fails immediately (note that currently curl in a Stackblitz Web Container environment doesn't support -f nor -S):

curl -sL https://deno.land/install.sh | sh
curl: socket hang up

Inspecting network traffic for the browser document via DevTools reveals that the first issue is a CORS issue:

Access to fetch at 'https://deno.land/install.sh' from origin 'https://something.w-credentialless-staticblitz.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I then tried pasting the contents of https://deno.land/install.sh into a file and running it directly:

sh install.sh
install.sh: line 7: unsupported shell syntax

For reference (and as the install.sh script might change with time), here is line 7:

if ! command -v unzip >/dev/null && ! command -v 7z >/dev/null; then

The Stackblitz Web Container shell (/bin/jsh/) appears to have limited functionality but as Stackblitz supports Node.js it seems to me that supporting Deno should also be feasible.

It might require some special setup from Stackblitz though. I've also created stackblitz/webcontainer-core#1608.

@bartlomieju bartlomieju added the suggestion suggestions for new features (yet to be agreed) label Nov 16, 2024
@kt3k
Copy link
Member

kt3k commented Nov 26, 2024

What happens if you run the below commands:

curl -o deno.zip "https://dl.deno.land/release/$(curl -s https://dl.deno.land/release-latest.txt)/deno-x86_64-unknown-linux-gnu.zip"
unzip deno.zip
./deno -v

@mfulton26
Copy link
Author

mfulton26 commented Nov 26, 2024

First hurdle: I cannot download straight into Stackblitz due to lack of CORS headers from Deno's download site:

Access to fetch at 'https://dl.deno.land/release//deno-x86_64-unknown-linux-gnu.zip' from origin 'https://vitejsvitexr7esd-ly13.w-corp-staticblitz.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Workaround: I can download to my local computer and then "upload" into Stackblitz env (it stores things in IndexedDB I think so I'm really just "copying" file(s) into web storage on my local computer).

Second hurdle: Stackblitz doesn't support "uploading" files larger than 10MB and deno.zip is ~50MB.

Individual files uploaded to StackBlitz cannot exceed 10MB. Please try again with a smaller file.

Third hurdle: Stackblitz env doesn't have unzip.

Workaround: I can unzip on my local machine, split the deflated deno executable into pieces, "upload" them into the Stackblitz env, and then reconstruct deno from the pieces using cat:

curl -o deno.zip "https://dl.deno.land/release/$(curl -s https://dl.deno.land/release-latest.txt)/deno-x86_64-unknown-linux-gnu.zip"
unzip deno.zip
split -b10m deno # produces files named xaa, xab, ..., xan
# deno-pieces contains the uploaded xa* filescat deno-pieces/* > deno.zip

Fourth hurdle: The cat command runs for some time but then fails. It does combine some of the files but not all of them. DevTools console reveals the following:

Uncaught (in promise) RangeError: Array buffer allocation failed
    at arrayBufferConstructor_DoNotInitialize (<anonymous>)
    at new Uint8Array (<anonymous>)
    at _0x1353ef.wbg.__wbg_new_8f67e318f15d7254 (filesystem-worker.88b6dd69.js:1:441807)
    at fs_bg.88b6dd69.wasm:0xe5f8
    at fs_bg.88b6dd69.wasm:0x493dc
    at fs_bg.88b6dd69.wasm:0x6f297
    at fs_bg.88b6dd69.wasm:0x6d3e7
    at _0x1e8d0b (filesystem-worker.88b6dd69.js:1:369997)
    at _0x207cad (filesystem-worker.88b6dd69.js:1:369615)

I tried combing pieces one at a time but then Stackblitz froze and reloading the env didn't work (usually the files are still there but Stackblitz must have detected a problem with them and deleted them).

I suspect that Stackblitz has done some special stuff with their web containers to make larger binaries like node, pnpm, yarn, etc. work as inspecting their size on the "filesystem" reveals really tiny, unrealistic sizes:

ls -la /usr/local/bin
total 2
drwxr-xr-x  1   root   root    13  Nov  26  10:56  ./                                              
drwxr-xr-x  1   root   root     2  Nov  26  10:56  ../                                             
-rwxr-xr-x  1   root   root    12  Nov  26  10:56  code*                                           
-rwxr-xr-x  1   root   root  1601  Nov  26  10:56  google-chrome*                                  
-rwxr-xr-x  1   root   root    12  Nov  26  10:56  jq*                                             
-rwxr-xr-x  1   root   root    12  Nov  26  10:56  loadenv*                                        
-rwxr-xr-x  1   root   root    12  Nov  26  10:56  node*                                           
lrwxrwxrwx  1  staff  staff    38  Nov  26  10:56  npm@ -> ../lib/node_modules/npm/bin/npm-cli.js  
lrwxrwxrwx  1  staff  staff    38  Nov  26  10:56  npx@ -> ../lib/node_modules/npm/bin/npx-cli.js  
lrwxrwxrwx  1  staff  staff    37  Nov  26  10:56  pnpm@ -> ../lib/node_modules/pnpm/bin/pnpm.cjs  
lrwxrwxrwx  1  staff  staff    37  Nov  26  10:56  pnpx@ -> ../lib/node_modules/pnpm/bin/pnpx.cjs  
-rwxr-xr-x  1   root   root    12  Nov  26  10:56  python3*                                        
-rwxr-xr-x  1   root   root    12  Nov  26  10:56  wasm*                                           
-rwxr-xr-x  1   root   root    12  Nov  26  10:56  xdg-open*                                       
lrwxrwxrwx  1  staff  staff    37  Nov  26  10:56  yarn@ -> ../lib/node_modules/yarn/dist/yarn.js

@kt3k
Copy link
Member

kt3k commented Nov 27, 2024

Ah, ok. Stackblitz WebContainer is not like docker container. It's not based on linux or any operating system, but it simulates Node.js using browser's JS engine. It can't execute binary executables like deno command. ref https://blog.stackblitz.com/posts/introducing-webcontainers/

I suspect that Stackblitz has done some special stuff with their web containers to make larger binaries like node, pnpm, yarn, etc.

That sounds correct. I think deno doesn't work in stackblitz unless stackblitz team does a similar work about Deno, simulating Deno APIs on browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

3 participants