網站搜尋

typescript - 在 Google Colab 測試 Deno Jupyter 核心


我在使用 Google Colab 安裝/配置時遇到問題。

  • 我的目標:在基於 Deno 的 Jupyter 筆記本核心中直接執行 Typescript。

  • 我的問題:我是否如預期正確安裝了所有東西,或者是否還需要另一個庫,才能允許 Javascript/Typescript 在我更改運行時類型後直接在筆記本中運行?

要重現我的步驟:

  1. 前往 Google Colab 並打開一個新的筆記本:https://colab.google/ ,然後在各自的筆記本單元格中直接運行以下每個命令。

  2. !pip 安裝 jupyterlab

Requirement already satisfied: jupyterlab in /usr/local/lib/python3.10/dist-packages (4.0.8)
Requirement already satisfied: async-lru>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from jupyterlab) (2.0.4)
....
  1. !curl -fsSL https://deno.land/x/install/install.sh | sudo DENO_INSTALL=/usr/local sh
######################################################################## 100.0%
Archive:  /usr/local/bin/deno.zip
  inflating: /usr/local/bin/deno     
Deno was installed successfully to /usr/local/bin/deno
Run 'deno --help' to get started 
  1. !deno --version
deno 1.38.0 (release, x86_64-unknown-linux-gnu)
v8 12.0.267.1
typescript 5.2.2
  1. !jupyter kernelspec list
Available kernels:
  deno       /root/.local/share/jupyter/kernels/deno
  ir         /usr/local/share/jupyter/kernels/ir
  python3    /usr/local/share/jupyter/kernels/python3
  1. !deno jupyter --unstable
ℹ️ Deno kernel is not yet installed, run `deno jupyter --unstable --install` to set it up
  1. !deno jupyter --unstable --install
[InstallKernelSpec] Installed kernelspec deno in /root/.local/share/jupyter/kernels/deno
✅ Deno kernelspec installed successfully.
  1. !deno run https://examples.deno.land/hello-world.ts
Download https://examples.deno.land/hello-world.ts
Hello, World!
  1. 如果我在一個單元格中運行以下代碼,它可以正常運行,但是
%%javascript
let x = 5;
let y = 2;
let z = x + y;
element.textContent = z

如預期的,JavaScript 不會直接在單元格內執行,除非我更改運行時。讓我們在下一步解決這個問題 :)

let x = 5;
let y = 2;
let z = x + y;
console.log(z);
File "<ipython-input-2-43a8c54cf62a>", line 1
    let x = 5;
        ^
SyntaxError: invalid syntax
  1. 執行時間 > 更改執行時間類型 > Deno

  1. 它只是顯示:正在連接,但什麼也沒發生,接著出現以下彈出窗口:

await connected: disconnected
Error: await connected: disconnected
    at https://ssl.gstatic.com/colaboratory-static/common/7ecc98b5a079533f6e1c231d23497bd7/external_polymer_binary.js:7118:372

我感謝任何對這個問題的幫助。提前感謝!