unexpected error: TypeError: Cannot read properties of undefined (reading 'locals')
vangj opened this issue · 9 comments
After installing tslab according to the documentation on Mac Ventura 13.3.1 (Apple M1 Pro) and starting a notebook (does not matter if it's JavaScript or TypeScript), the following error is shown upon executing a cell (eg. console.log('hello')
):
unexpected error: TypeError: Cannot read properties of undefined (reading 'locals')
at remainingDecls (/Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/converter.js:437:36)
at Object.convert (/Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/converter.js:313:23)
at Object.execute (/Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/executor.js:140:38)
at JupyterHandlerImpl.handleExecuteImpl (/Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/jupyter.js:223:38)
at /Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/jupyter.js:181:57
at async JupyterHandlerImpl.handleExecute (/Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/jupyter.js:181:21)
at async ZmqServer.handleExecute (/Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/jupyter.js:379:25)
at async ZmqServer.handleShellMessage (/Users/super/.nvm/versions/node/v16.20.0/lib/node_modules/tslab/dist/jupyter.js:324:21)
It took a bit of a miracle to even install tslab, but here were the steps I took.
brew update -d --auto-update --verbose --force --debug
brew install cmake
brew install zeromq
brew install pkgconfig
npm install -g tslab
tslab install --version
tslab install --python=python
jupyter kernelspec list
For NodeJS, I am using nvm
v0.39.1. Thus, I can switch between the following 3 node versions.
- v14.21.2
- v16.20.0
- v18.16.0
The error above happens only on v16 and v18 inside a notebook. On v14, I see nothing indicating an error in the notebook but it hangs and just keeps indicating some background processing is happening; when I look at the console from where I ran Jupyter Lab, I see the following message repeated over and over. I'm guessing v14 is not supported?
[I 2023-04-28 07:04:55.646 ServerApp] Kernel started: ea949a02-e6a9-4f7c-a7a1-f91107909de6
dyld[47796]: missing symbol called
[I 2023-04-28 07:04:58.634 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (1/5), new random ports
dyld[47799]: missing symbol called
FWIW, here are some other information about my setup/environment using conda v23.3.1.
jupyter 1.0.0 py39hecd8cb5_8
jupyter-lsp 1.5.1 pyhd8ed1ab_0 conda-forge
jupyter-server-mathjax 0.2.6 pyhc268e32_0 conda-forge
jupyter-sphinx 0.4.0 pypi_0 pypi
jupyter_client 7.4.9 py39hecd8cb5_0
jupyter_console 6.6.2 py39hecd8cb5_0
jupyter_core 5.2.0 py39hecd8cb5_0
jupyter_server 1.23.4 py39hecd8cb5_0
jupyterlab 3.5.3 py39hecd8cb5_0
jupyterlab-git 0.39.2 pyhd8ed1ab_0 conda-forge
jupyterlab-lsp 3.10.2 pyhd8ed1ab_0 conda-forge
jupyterlab_pygments 0.1.2 py_0
jupyterlab_server 2.19.0 py39hecd8cb5_0
jupyterlab_widgets 1.0.0 pyhd3eb1b0_1
Was literally about to open up an issue for this problem.
$> jupyter console --kernel=tslab
unknown msg_type: history_request
Jupyter console 6.4.0
TypeScript
In [1]: 1
unexpected error: TypeError: Cannot read properties of undefined (reading 'locals')
at remainingDecls (/Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/converter.js:437:36)
at Object.convert (/Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/converter.js:313:23)
at Object.execute (/Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/executor.js:140:38)
at JupyterHandlerImpl.handleExecuteImpl (/Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/jupyter.js:223:38)
at /Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/jupyter.js:181:57
at async JupyterHandlerImpl.handleExecute (/Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/jupyter.js:181:21)
at async ZmqServer.handleExecute (/Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/jupyter.js:379:25)
at async ZmqServer.handleShellMessage (/Users/tiansivive/.nvm/versions/node/v16.13.1/lib/node_modules/tslab/dist/jupyter.js:324:21)
Shutting down kernel
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<ZMQTerminalInteractiveShell.interact() done, defined at /Users/tiansivive/opt/anaconda3/lib/python3.9/site-packages/jupyter_console/ptshell.py:635> exception=KeyError('execution_count')>
Traceback (most recent call last):
File "/Users/tiansivive/opt/anaconda3/lib/python3.9/site-packages/jupyter_console/ptshell.py", line 648, in interact
self.run_cell(code, store_history=True)
File "/Users/tiansivive/opt/anaconda3/lib/python3.9/site-packages/jupyter_console/ptshell.py", line 730, in run_cell
self.handle_execute_reply(msg_id, timeout=0.05)
File "/Users/tiansivive/opt/anaconda3/lib/python3.9/site-packages/jupyter_console/ptshell.py", line 768, in handle_execute_reply
self.execution_count = int(content["execution_count"] + 1)
KeyError: 'execution_count'
Seems like this is only an issue in the latest release.
Uninstalling and installing v1.0.16 via
npm i -g tslab@1.0.16
fixes the issue.
Looks like there's been some changes to src/converter.ts
which are causing the issue
Thank you for the report. The TypeScript compiler's watch mechanism changed in v4.9 (tslab: v1.0.18) and I think the change in TypeScript compiler is suspicous although I cannot reproduce the issue on Linux Node.js.
@tiansivive Does this happen from which version of tslab? Do tslab v1.0.17 and v1.0.18 work in your environment?
This happens on v1.0.19. I'll try to uninstall and downgrade and report back. Thanks.
I can confirm that this issue does not happen on v1.0.16 using Node v18.16.0. Thanks for the help! Please close the ticket if appropriate.
@yunabe oh, I didn't realise I skipped those versions. I tried them now and v1.0.17 works but not v1.0.18.
So it does seem like it's the watch mechanism with TS 4.9
For the record, I'm running a MacBook Pro on Monterrey (12.4)
I enabled GitHub Actions to run continuous tests on Windows and MacOS.
I confirmed tests are green in all operating systems with TypeScript 4.6 (https://github.com/yunabe/tslab/actions/runs/4954329573), but tests fail in the main branch with TypeScript 5 (https://github.com/yunabe/tslab/actions/runs/4953911999).
The root cause of the problme was TypeScript changed the file normalization logic in environments with case-insensitive filesystems (e.g. Windows, MacOS). I implemeneted a workaround and released v1.0.21
with TypeScript 5.0.
Could you try v1.0.21
and let me know if it does not work?
Thanks,
yunabe