coder / code-server

VS Code in the browser
https://coder.com
MIT License
67.88k stars 5.58k forks source link

Cannot find module './lib/binding/napi-v3/argon2.node'[Bug]: #5561

Closed RealEthanPlayzDev closed 2 months ago

RealEthanPlayzDev commented 2 years ago

Is there an existing issue for this?

OS/Web Information

Steps to Reproduce

  1. Use the install script to install code-server in the standalone method
  2. Try running code-server (like code-server --version)
  3. It fails.

Expected

code-server to run fine without any errors.

Actual

code-server crashes with the following error:

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module './lib/binding/napi-v3/argon2.node'
Require stack:
- /home/radiatedexodus/.local/lib/code-server-4.7.0/node_modules/argon2/argon2.js
- /home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/util.js
- /home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/cli.js
- /home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/entry.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/radiatedexodus/.local/lib/code-server-4.7.0/node_modules/argon2/argon2.js:6:25)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/node_modules/argon2/argon2.js',
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/util.js',
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/cli.js',
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/entry.js'
  ]
}

Logs

Can't run code-server at all, following error thrown:

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module './lib/binding/napi-v3/argon2.node'
Require stack:
- /home/radiatedexodus/.local/lib/code-server-4.7.0/node_modules/argon2/argon2.js
- /home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/util.js
- /home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/cli.js
- /home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/entry.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/radiatedexodus/.local/lib/code-server-4.7.0/node_modules/argon2/argon2.js:6:25)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/node_modules/argon2/argon2.js',
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/util.js',
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/cli.js',
    '/home/radiatedexodus/.local/lib/code-server-4.7.0/out/node/entry.js'
  ]
}

Screenshot/Video

Screenshot_20220916_135343

Does this issue happen in VS Code or GitHub Codespaces?

Are you accessing code-server over HTTPS?

Notes

jsjoeio commented 2 years ago

First, thanks for the thorough notes! Second, sorry to hear this is happening. code-server used to work so well on Termux and the last few months haven't been great.

Could you try building node-argon2 from source and seeing if that works? https://github.com/ranisalt/node-argon2#before-installing

RealEthanPlayzDev commented 2 years ago

@jsjoeio Nope, I don't think it worked: (followed installation and rebuild steps, both failed) Screenshot_20220916-224719_Termux

I believe I've been starting to have issues with installating a standalone release ever since v4.5.1 when I reset my Termux data to redo it from scratch again, before that I used to be able to install v4.0.0, v4.0.2, v4.0.5

jsjoeio commented 2 years ago

Thanks for trying! Let me raise an issue upstream and see if the node-argon2 team has recommendations

jsjoeio commented 2 years ago

Wait one last thing, can you try npm_config_build_from_source=true CXX=g++ npm install argon2 in the same directory you were testing before?

RealEthanPlayzDev commented 2 years ago

@jsjoeio No, the command still doesn't work (I assume you are supposed to execute npm install related commands in the installation directory, specifically ~/.local/lib/code-server-4.7.0, correct me if this is wrong) Screenshot_20220917-094618_Termux

RealEthanPlayzDev commented 2 years ago

I've tried the suggestion in https://github.com/coder/code-server/issues/5184#issuecomment-1186854948 which is going to the argon2 folder in node_modules (~/.local/lib/code-server-4.7.0/node_modules/argon2) and do npm install, this was the result:

[radiatedexodus code-server-4.7.0]$ cd node_modules/argon2
[radiatedexodus argon2]$ ls
LICENSE  README.md  argon2  argon2.d.ts  argon2.js  binding.gyp  build-tmp-napi-v3  lib  package.json  src
[radiatedexodus argon2]$ npm install
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/color-support reason: Invalid response body while trying to fetch https://registry.npmjs.org/color-support: ENOENT: no such file or directory, rename '/home/radiatedexodus/.npm/_cacache/tmp/f1e0d306' -> '/home/radiatedexodus/.npm/_cacache/content-v2/sha512/5d/61/71054f33939b04a7c6db0bc13c8acc048919f567fe4d5ed67a969f0486fabeb3d18830e5ffe68f40e6d7bc9ea940de2bd9ec46525a04b10f6f7cd3b52f71'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/radiatedexodus/.npm/_logs/2022-09-17T03_03_16_867Z-debug-0.log

This was also one of the reasons I didn't want to bother using npm to deal with it, it has strange issues with not being able to find cached files and I'm getting tired of dealing with them (I've said this in the notes)

  • Using npm directly doesn't really work for me, the last time I've used it, no matter what I do I couldn't upgrade code-server when a new release was released. (either saying it can't find some cached files, or it doesn't do anything and make me waste time)

Additionally, I have to do a correction for the part where I said the early 4.x.x versions worked fine:

jsjoeio commented 2 years ago

Thank you for the thorough explanation @RealEthanPlayzDev! I can empathize, this sounds frustrating. I am not sure myself or @code-asher have bandwidth to dive deep on this right now but I'll make it high priority and we can look at this in the upcoming or next milestone.

RealEthanPlayzDev commented 2 years ago

@jsjoeio I understand. I'll wait for the fix, you can take your time!

jsjoeio commented 2 years ago

Thanks for understanding!

Sonotoki-da commented 2 years ago

It works when you download a tar.gz release for arm64, and run it direcrtly, executing code-server which is stored in the bin folder.

My specs are: termux the latest version (installed from github releases) proot'ed into manjaro-aarch64 node 18

The result: Screenshot_2022-09-23-02-10-51-464_com termux

But yes, the errors are the same when installed via the script.

jsjoeio commented 2 years ago

@Sonotoki-da wow, thanks for sharing! I wonder then if we can just create a copy of that tar.gz and call it termux.tar.gz which would resolve https://github.com/coder/code-server/issues/5515

thoughts @code-asher?

RealEthanPlayzDev commented 2 years ago

It works when you download a tar.gz release for arm64, and run it direcrtly, executing code-server which is stored in the bin folder.

I wonder what tar.gz did the script download then 🤔 @Sonotoki-da Anyways, thanks for telling me that! I'll try it real quick

EDIT: It worked! Screenshot_20220923-073807_Termux

RealEthanPlayzDev commented 2 years ago

@jsjoeio I suppose code-server uses symlinks right? I think those links broke in the process of installation (I tried moving the extracted code-server from the comment above to ~/.local/lib and it gave back me argon2 error, rm-rf'ed the folder and re-extracted the tar with tar -xvf /path/to/code-server-tar.tar.gz in lib folder at .local and it worked fine)

jsjoeio commented 2 years ago

I think those links broke in the process of installation

Holy cow, that's amazing insight. We've had troubles with Termux in the past and maybe this is the clue we've been missing. Thank you so much for trying and confirming!

@code-asher does this spark any ideas?

code-asher commented 2 years ago

Ah yeah if you are using something like proot I believe the prebuild should work. Running directly on Termux should not work though as that would require specifically compiling for Termux.

I think our Termux docs mention proot but I wonder if our installer has some issues in that scenario like pulling the wrong prebuild. It would be worthwhile to verify the install script's behavior in proot with a dry run to see what is trying to do.

There are some symlinks but I am not sure how they would break. It would make sense to see if we can reliably reproduce.

utkustnr commented 1 year ago

I think those links broke in the process of installation

Holy cow, that's amazing insight. We've had troubles with Termux in the past and maybe this is the clue we've been missing. Thank you so much for trying and confirming!

@code-asher does this spark any ideas?

Sorry to bump the issue but I've had the same problem with op but mine was inside termux shell, not proot. Since links are a known issue I wanted to share my own insight to the problem. When you ignore the argon2 issue with yarn / npm and run install script it gives this output :

~ $ curl -fsSL https://code-server.dev/install.sh | sh
Linux 4.9.319-Phenix
Unsupported package manager.
Falling back to standalone installation.
Installing v4.8.0 of the arm64 release from GitHub.

+ Reusing ~/.cache/code-server/code-server-4.8.0-linux-arm64.tar.gz
+ mkdir -p ~/.local
+ mkdir -p ~/.local/lib ~/.local/bin
+ tar -C ~/.local/lib -xzf ~/.cache/code-server/code-server-4.8.0-linux-arm64.tar.gz
tar: code-server-4.8.0-linux-arm64/node_modules/argon2/build-tmp-napi-v3/Release/obj.target/argon2.node: Cannot hard link to ‘code-server-4.8.0-linux-arm64/node_modules/argon2/lib/binding/napi-v3/argon2.node’: Permission denied
tar: code-server-4.8.0-linux-arm64/node_modules/argon2/build-tmp-napi-v3/Release/argon2.a: Cannot hard link to ‘code-server-4.8.0-linux-arm64/node_modules/argon2/build-tmp-napi-v3/Release/obj.target/argon2.a’: Permission denied
tar: code-server-4.8.0-linux-arm64/node_modules/argon2/build-tmp-napi-v3/Release/argon2.node: Cannot hard link to ‘code-server-4.8.0-linux-arm64/node_modules/argon2/lib/binding/napi-v3/argon2.node’: Permission denied
tar: code-server-4.8.0-linux-arm64/lib/vscode/node_modules/native-watchdog/build/Release/watchdog.node: Cannot hard link to ‘code-server-4.8.0-linux-arm64/lib/vscode/node_modules/native-watchdog/build/Release/obj.target/watchdog.node’: Permission denied
tar: code-server-4.8.0-linux-arm64/lib/vscode/node_modules/spdlog/build/Release/spdlog.node: Cannot hard link to ‘code-server-4.8.0-linux-arm64/lib/vscode/node_modules/spdlog/build/Release/obj.target/spdlog.node’: Permission denied
tar: code-server-4.8.0-linux-arm64/lib/vscode/node_modules/@parcel/watcher/build/Release/nothing.a: Cannot hard link to ‘code-server-4.8.0-linux-arm64/lib/vscode/node_modules/@parcel/watcher/build/node-addon-api/nothing.a’: Permission denied
tar: code-server-4.8.0-linux-arm64/lib/vscode/node_modules/@parcel/watcher/build/Release/watcher.node: Cannot hard link to ‘code-server-4.8.0-linux-arm64/lib/vscode/node_modules/@parcel/watcher/build/Release/obj.target/watcher.node’: Permission denied
tar: Exiting with failure status due to previous errors
~ $

But since I have root access why shouldn't I use it when it's just basic links right? This is the output when you fix linking issue :

~ $ node -v
v16.18.0
~ $ tsu
.../files/home # export HOME="/data/data/com.termux/files/home"   
~ # curl -fsSL https://code-server.dev/install.sh | sh
Linux 4.9.319-Phenix
Unsupported package manager.
Falling back to standalone installation.
Installing v4.8.0 of the arm64 release from GitHub.

+ mkdir -p ~/.cache/code-server
+ curl -#fL -o ~/.cache/code-server/code-server-4.8.0-linux-arm64.tar.gz.incomplete -C - https://github.com/coder/code-server/releases/download/v4.8.0/code-server-4.8.0-linux-arm64.tar.gz
######################################################################## 100.0%
+ mv ~/.cache/code-server/code-server-4.8.0-linux-arm64.tar.gz.incomplete ~/.cache/code-server/code-server-4.8.0-linux-arm64.tar.gz
+ mkdir -p ~/.local
+ mkdir -p ~/.local/lib ~/.local/bin
+ tar -C ~/.local/lib -xzf ~/.cache/code-server/code-server-4.8.0-linux-arm64.tar.gz
+ mv -f ~/.local/lib/code-server-4.8.0-linux-arm64 ~/.local/lib/code-server-4.8.0
+ ln -fs ~/.local/lib/code-server-4.8.0/bin/code-server ~/.local/bin/code-server

Standalone release has been installed into ~/.local/lib/code-server-4.8.0

Extend your path to use code-server:
  PATH="$HOME/.local/bin:$PATH"
Then run with:
  code-server
~ # echo $PATH
/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets:/system/bin:/system/xbin:/sbin:/sbin/bin
~ # export PATH="$HOME/.local/bin:$PATH"
~ # echo $PATH
/data/data/com.termux/files/home/.local/bin:/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets:/system/bin:/system/xbin:/sbin:/sbin/bin
~ # code-server
/data/data/com.termux/files/home/.local/bin/code-server: 28: exec: /data/data/com.termux/files/home/.local/lib/code-server-4.8.0/lib/node: not found
~ # ln -fs /data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/home/.local/lib/code-server-4.8.0/lib/
~ # code-server
node:internal/modules/cjs/loader:1239
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: dlopen failed: library "libstdc++.so.6" not found
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1239:18)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/data/data/com.termux/files/home/.local/lib/code-server-4.8.0/node_modules/argon2/argon2.js:6:25)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12) {
  code: 'ERR_DLOPEN_FAILED'
}
~ #

As you can see node wasn't recognized so I had to link it manually as well. I couldn't go past this I'm afraid. Let me know if these help. Thanks.

Edit: Termux has mingw-w64-gcc-libs package that includes libstdc++ but installing it did not change anything whatsoever.

jsjoeio commented 1 year ago

Thank you for sharing all that! One idea, which we've tried in the past is switching to @node-rs/argon2 (see here: https://github.com/coder/code-server/issues/4804#issuecomment-1030338395). We may investigate that again and see if using --force with the npm install works.

code-asher commented 1 year ago

Yeah I would not expect the standalone arm64 GitHub release to work on Android. I believe we would need to compile specifically for Termux rather than generic Linux arm64. We should fix the install script trying to download a release that will not work and make it use npm install instead.

utkustnr commented 1 year ago

Hey, I know this is not directly connected to argon2 issue but since I bringed up termux I might as well follow up on it. Apparently termux has a user repository with it's own code-server install script. (see here: code-server) Installing code-server was as easy as pkg install code-server after installing repo. Install script was created just a few days ago as well, figured I should give a heads up.

code-asher commented 1 year ago

Good point! I think we can close this issue once we get the install script changes done in https://github.com/coder/code-server/issues/5745.

haruki-py commented 6 months ago

Doing as per termux docs worked for me.