coder / code-server

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

Unable to install on FreeBSD 13.2 #6842

Open jpcastberg opened 2 weeks ago

jpcastberg commented 2 weeks ago

Is there an existing issue for this?

OS/Web Information

Steps to Reproduce

  1. Install node 20:

    pkg install npm-node20-10.8.1
  2. Install dependencies per instructions described here

    pkg install -y git python npm-node20 pkgconf
    pkg install -y libinotify
  3. Attempt to install via install script:

    curl -fsSL https://code-server.dev/install.sh | sh

Expected

code-server should install successfully

Actual

errors are generated during the install process, installation fails.

Logs

curl -fsSL https://code-server.dev/install.sh | sh
FreeBSD 13.2-RELEASE-p10
Installing latest from npm.

sh: NPM_PATH: not found
Installing with npm.

+ npm install -g code-server --unsafe-perm
npm error code 1
npm error path /usr/local/lib/node_modules/code-server
npm error command failed
npm error command sh -c sh ./postinstall.sh
npm error Installing Code dependencies...
npm error User agent: npm/10.8.1 node/v20.14.0 freebsd x64 workspaces/false
npm error You may not have the required dependencies to build the native modules.
npm error Please see https://github.com/coder/code-server/blob/main/docs/npm.md
npm error npm error code 1
npm error npm error path /usr/local/lib/node_modules/code-server/lib/vscode/node_modules/node-pty
npm error npm error command failed
npm error npm error command sh -c node-gyp rebuild
npm error npm error gmake: Entering directory '/usr/local/lib/node_modules/code-server/lib/vscode/node_modules/node-pty/build'
npm error npm error   TOUCH Release/obj.target/node_modules/node-addon-api/node_addon_api_except.stamp
npm error npm error   CXX(target) Release/obj.target/pty/src/unix/pty.o
npm error npm error gmake: Leaving directory '/usr/local/lib/node_modules/code-server/lib/vscode/node_modules/node-pty/build'
npm error npm error gyp info it worked if it ends with ok
npm error npm error gyp info using node-gyp@10.1.0
npm error npm error gyp info using node@20.14.0 | freebsd | x64
npm error npm error gyp info find Python using Python version 3.11.9 found at "/usr/local/bin/python3.11"
npm error npm error gyp info spawn /usr/local/bin/python3.11
npm error npm error gyp info spawn args [
npm error npm error gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm error npm error gyp info spawn args 'binding.gyp',
npm error npm error gyp info spawn args '-f',
npm error npm error gyp info spawn args 'make',
npm error npm error gyp info spawn args '-I',
npm error npm error gyp info spawn args '/usr/local/lib/node_modules/code-server/lib/vscode/node_modules/node-pty/build/config.gypi',
npm error npm error gyp info spawn args '-I',
npm error npm error gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm error npm error gyp info spawn args '-I',
npm error npm error gyp info spawn args '/root/.cache/node-gyp/20.14.0/include/node/common.gypi',
npm error npm error gyp info spawn args '-Dlibrary=shared_library',
npm error npm error gyp info spawn args '-Dvisibility=default',
npm error npm error gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/20.14.0',
npm error npm error gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
npm error npm error gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/20.14.0/<(target_arch)/node.lib',
npm error npm error gyp info spawn args '-Dmodule_root_dir=/usr/local/lib/node_modules/code-server/lib/vscode/node_modules/node-pty',
npm error npm error gyp info spawn args '-Dnode_engine=v8',
npm error npm error gyp info spawn args '--depth=.',
npm error npm error gyp info spawn args '--no-parallel',
npm error npm error gyp info spawn args '--generator-output',
npm error npm error gyp info spawn args 'build',
npm error npm error gyp info spawn args '-Goutput_dir=.'
npm error npm error gyp info spawn args ]
npm error npm error gyp info spawn gmake
npm error npm error gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm error npm error ../src/unix/pty.cc:310:22: error: invalid use of incomplete type 'termios'
npm error npm error   310 |   struct termios t = termios();
npm error npm error       |                      ^~~~~~~~~
npm error npm error /usr/include/libutil.h:85:8: note: forward declaration of 'termios'
npm error npm error    85 | struct termios;
npm error npm error       |        ^
npm error npm error ../src/unix/pty.cc:310:18: error: variable has incomplete type 'struct termios'
npm error npm error   310 |   struct termios t = termios();
npm error npm error       |                  ^
npm error npm error /usr/include/libutil.h:85:8: note: forward declaration of 'termios'
npm error npm error    85 | struct termios;
npm error npm error       |        ^
npm error npm error ../src/unix/pty.cc:312:7: error: member access into incomplete type 'struct termios'
npm error npm error   312 |   term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT;
npm error npm error       |       ^
npm error npm error /usr/include/libutil.h:85:8: note: forward declaration of 'termios'
npm error npm error    85 | struct termios;
npm error npm error       |        ^
npm error npm error ../src/unix/pty.cc:312:19: error: use of undeclared identifier 'ICRNL'
npm error npm error   312 |   term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT;
npm error npm error       |                   ^
npm error npm error ../src/unix/pty.cc:312:27: error: use of undeclared identifier 'IXON'
npm error npm error   312 |   term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT;
npm error npm error       |                           ^
npm error npm error ../src/unix/pty.cc:312:34: error: use of undeclared identifier 'IXANY'
npm error npm error   312 |   term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT;
npm error npm error       |                                  ^
npm error npm error ../src/unix/pty.cc:312:42: error: use of undeclared identifier 'IMAXBEL'
npm error npm error   312 |   term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT;
npm error npm error       |                                          ^
npm error npm error ../src/unix/pty.cc:312:52: error: use of undeclared identifier 'BRKINT'
npm error npm error   312 |   term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT;
npm error npm error       |                                                    ^
npm error npm error ../src/unix/pty.cc:318:7: error: member access into incomplete type 'struct termios'
npm error npm error   318 |   term->c_oflag = OPOST | ONLCR;
npm error npm error       |       ^
npm error npm error /usr/include/libutil.h:85:8: note: forward declaration of 'termios'
npm error npm error    85 | struct termios;
npm error npm error       |        ^
npm error npm error ../src/unix/pty.cc:318:19: error: use of undeclared identifier 'OPOST'
npm error npm error   318 |   term->c_oflag = OPOST | ONLCR;
npm error npm error       |                   ^
npm error npm error ../src/unix/pty.cc:318:27: error: use of undeclared identifier 'ONLCR'
npm error npm error   318 |   term->c_oflag = OPOST | ONLCR;
npm error npm error       |                           ^
npm error npm error ../src/unix/pty.cc:319:7: error: member access into incomplete type 'struct termios'
npm error npm error   319 |   term->c_cflag = CREAD | CS8 | HUPCL;
npm error npm error       |       ^
npm error npm error /usr/include/libutil.h:85:8: note: forward declaration of 'termios'
npm error npm error    85 | struct termios;
npm error npm error       |        ^
npm error npm error ../src/unix/pty.cc:319:19: error: use of undeclared identifier 'CREAD'
npm error npm error   319 |   term->c_cflag = CREAD | CS8 | HUPCL;
npm error npm error       |                   ^
npm error npm error ../src/unix/pty.cc:319:27: error: use of undeclared identifier 'CS8'
npm error npm error   319 |   term->c_cflag = CREAD | CS8 | HUPCL;
npm error npm error       |                           ^
npm error npm error ../src/unix/pty.cc:319:33: error: use of undeclared identifier 'HUPCL'
npm error npm error   319 |   term->c_cflag = CREAD | CS8 | HUPCL;
npm error npm error       |                                 ^
npm error npm error ../src/unix/pty.cc:320:7: error: member access into incomplete type 'struct termios'
npm error npm error   320 |   term->c_lflag = ICANON | ISIG | IEXTEN | ECHO | ECHOE | ECHOK | ECHOKE | ECHOCTL;
npm error npm error       |       ^
npm error npm error /usr/include/libutil.h:85:8: note: forward declaration of 'termios'
npm error npm error    85 | struct termios;
npm error npm error       |        ^
npm error npm error ../src/unix/pty.cc:320:19: error: use of undeclared identifier 'ICANON'
npm error npm error   320 |   term->c_lflag = ICANON | ISIG | IEXTEN | ECHO | ECHOE | ECHOK | ECHOKE | ECHOCTL;
npm error npm error       |                   ^
npm error npm error ../src/unix/pty.cc:320:28: error: use of undeclared identifier 'ISIG'
npm error npm error   320 |   term->c_lflag = ICANON | ISIG | IEXTEN | ECHO | ECHOE | ECHOK | ECHOKE | ECHOCTL;
npm error npm error       |                            ^
npm error npm error ../src/unix/pty.cc:320:35: error: use of undeclared identifier 'IEXTEN'
npm error npm error   320 |   term->c_lflag = ICANON | ISIG | IEXTEN | ECHO | ECHOE | ECHOK | ECHOKE | ECHOCTL;
npm error npm error       |                                   ^
npm error npm error fatal error: too many errors emitted, stopping now [-ferror-limit=]
npm error npm error 20 errors generated.
npm error npm error gmake: *** [pty.target.mk:109: Release/obj.target/pty/src/unix/pty.o] Error 1
npm error npm error gyp ERR! build error 
npm error npm error gyp ERR! stack Error: `gmake` failed with exit code: 2
npm error npm error gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:209:23)
npm error npm error gyp ERR! System FreeBSD 13.2-RELEASE-p10
npm error npm error gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm error npm error gyp ERR! cwd /usr/local/lib/node_modules/code-server/lib/vscode/node_modules/node-pty
npm error npm error gyp ERR! node -v v20.14.0
npm error npm error gyp ERR! node-gyp -v v10.1.0
npm error npm error gyp ERR! not ok
npm error npm error A complete log of this run can be found in: /root/.npm/_logs/2024-06-15T19_53_56_427Z-debug-0.log
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-06-15T19_53_52_122Z-debug-0.log

Screenshot/Video

No response

Does this bug reproduce in native VS Code?

This cannot be tested in native VS Code

Does this bug reproduce in GitHub Codespaces?

This cannot be tested in GitHub Codespaces

Are you accessing code-server over a secure context?

Notes

Thank you in advance for the help - I am very excited to use code-server for work as it now supports node 20, which we have on our remote machines. Happy to do as much troubleshooting as needed.

chenrui333 commented 2 weeks ago

I can see something similar with 4.90.2 build on the homebrew side

npm error gyp verb node dev dir /private/tmp/code-server-20240615-37528-12y8ws/package/.brew_home/Library/Caches/node-gyp/20.14.0
npm error gyp verb python /Applications/Xcode.app/Contents/Developer/usr/bin/python3
npm error gyp verb `which` succeeded for `make` /opt/homebrew/Library/Homebrew/shims/mac/super/make
npm error gyp verb bin symlinks created symlink to "/Applications/Xcode.app/Contents/Developer/usr/bin/python3" in "/private/tmp/code-server-20240615-37528-12y8ws/package/lib/vscode/node_modules/kerberos/build/node_gyp_bins" and added to PATH
npm error gyp info spawn make
npm error gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
npm error In file included from ../src/kerberos.cc:1:
npm error In file included from ../src/kerberos.h:11:
npm error In file included from ../node_modules/node-addon-api/napi.h:2981:
npm error ../node_modules/node-addon-api/napi-inl.h:64:12: error: no matching function for call to 'napi_add_finalizer'
npm error   status = napi_add_finalizer(env, obj, data, finalizer, hint, nullptr);
npm error            ^~~~~~~~~~~~~~~~~~
npm error ../node_modules/node-addon-api/napi-inl.h:2192:29: note: in instantiation of function template specialization 'Napi::details::AttachData<Napi::MethodCallbackData<node_kerberos::KerberosClient, Napi::Value (*)(const Napi::CallbackInfo &)>>' requested here
npm error     status = Napi::details::AttachData(env, *result, data);
npm error                             ^
npm error ../node_modules/node-addon-api/napi-inl.h:4165:16: note: in instantiation of function template specialization 'Napi::CreateFunction<Napi::MethodCallbackData<node_kerberos::KerberosClient, Napi::Value (*)(const Napi::CallbackInfo &)>>' requested here
npm error       status = CreateFunction(env,
npm error                ^
npm error ../node_modules/node-addon-api/napi-inl.h:4224:10: note: in instantiation of member function 'Napi::ObjectWrap<node_kerberos::KerberosClient>::DefineClass' requested here
npm error   return DefineClass(env,
npm error          ^
npm error ../src/kerberos.cc:42:9: note: in instantiation of member function 'Napi::ObjectWrap<node_kerberos::KerberosClient>::DefineClass' requested here
npm error         DefineClass(env,
npm error         ^
benz0li commented 2 weeks ago

@jpcastberg Delete your /root/.cache/node-gyp directory and try again.

The error is caused by node-pty. 👉 Check https://github.com/microsoft/node-pty for possible issues on FreeBSD 13.

jpcastberg commented 2 weeks ago

@benz0li Thanks for the direction - no dice though :( I don't see any issues in node-pty, open or closed that seem to relate to what I'm seeing. Though - I do see that I have the termios header file on the machine:

$ ls /usr/include | grep termios
termios.h

I have pretty limited knowledge of c, but it seems like it's not looking in the right place for my header files when node-pty's gyp script runs. Am going to attempt debugging this tonight...

jpcastberg commented 2 weeks ago

Well - the good news is that for node-pty, all I needed to do was import the header file in the right block. I opened a pull request over there to fix that https://github.com/microsoft/node-pty/pull/688 . Unfortunately, I've hit another node-gyp built addon in vscode that isn't playing nice with Freebsd - Kerberos:

> kerberos@2.1.0 install
> prebuild-install --runtime napi || node-gyp rebuild

prebuild-install warn install No prebuilt binaries found (target=4 runtime=napi arch=x64 libc= platform=freebsd)
gyp info it worked if it ends with ok
gyp info using node-gyp@10.1.0
gyp info using node@20.14.0 | freebsd | x64
gyp info find Python using Python version 3.11.9 found at "/usr/local/bin/python3.11"

gyp info spawn /usr/local/bin/python3.11
gyp info spawn args [
gyp info spawn args '/home/john/kerberos/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/home/john/kerberos/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/john/kerberos/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/root/.cache/node-gyp/20.14.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/20.14.0',
gyp info spawn args '-Dnode_gyp_dir=/home/john/kerberos/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/20.14.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/home/john/kerberos',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn gmake
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
gmake: Entering directory '/home/john/kerberos/build'
  CXX(target) Release/obj.target/kerberos/src/kerberos.o
In file included from ../src/kerberos.cc:1:
In file included from ../src/kerberos.h:13:
In file included from ../src/kerberos_common.h:13:
../src/win32/kerberos_sspi.h:22:10: fatal error: 'windows.h' file not found
   22 | #include <windows.h>
      |          ^~~~~~~~~~~
1 error generated.
gmake: *** [kerberos.target.mk:102: Release/obj.target/kerberos/src/kerberos.o] Error 1
gmake: Leaving directory '/home/john/kerberos/build'
gyp ERR! build error 
gyp ERR! stack Error: `gmake` failed with exit code: 2
gyp ERR! stack at ChildProcess.<anonymous> (/home/john/kerberos/node_modules/node-gyp/lib/build.js:209:23)
gyp ERR! System FreeBSD 13.2-RELEASE-p10
gyp ERR! command "/usr/local/bin/node" "/home/john/kerberos/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /home/john/kerberos
gyp ERR! node -v v20.14.0
gyp ERR! node-gyp -v v10.1.0
gyp ERR! not ok 

This Kerberos project, another vscode dependency, makes no mention of FreeBSD support - I take it that in order to run code-server, I'll need to make all of vscode's dependencies build nicely?

Again, thank ya'll for your help :)

benz0li commented 2 weeks ago

Cross reference:

code-asher commented 2 weeks ago

The kerberos dependency is imported on demand, so if you are not using Kerberos then there should be no negative side effects to not having the dependency.

The only issue I could see is that if the problem building kerberos causes npm to abort and not install some other required dependency, but I am not sure if npm is like this or if it always tries to install as much as it can.

If the former, this would be an annoying workaround, but one could download the tarball, remove kerberos from lib/vscode/package.json and then run npm install in the root.

But maybe there is a more clever way of omitting a dependency from the user side. IMO it should be made an optional dependency; maybe that is something we should patch, or maybe they would accept it upstream.

jpcastberg commented 2 weeks ago

I got it mostly working, though terminal and workspace search in files seem to be broken. Here are the steps:

run:

pkg install git npm-node20 krb5-devel
git clone https://github.com/mongodb-js/kerberos
git clone https://github.com/microsoft/node-pty.git
cd node-pty; npm install; cd ..

Then modify the following code in the kerberos directory to match the below (From: https://github.com/coder/code-server/issues/6499#issuecomment-1774897502):

kerberos/binding.gyp:

'include_dirs': [
    "/usr/local/include",
    "<!(node -p \"require('node-addon-api').include_dir\")"
],
['OS=="mac" or OS=="linux" or OS=="freebsd"', {

kerberos/src/kerberos_common.h:

#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)

then:

cd kerberos; npm install; cd ..;

then:

npm pack code-server;
tar -xzf code-server-4.90.2.tgz;

this will create a directory called package - now modify:

package/lib/vscode/package.json

and change the lines for kerberos and node-pty and point them to the directories of the repos you downloaded:

"kerberos": "file:/path/to/kerberos",
"node-pty": "file:/path/to/node-pty",

then:

cd package;
npm install -g --unsafe-perm

This should give you the code-server binary in your path, which you can run. If you're like me and are running code-server on a remote machine, run as so:

code-server --bind-addr '0.0.0.0:8080'

It'll print the location of a file where you can get your password. Hope this helps someone!

code-asher commented 2 weeks ago

Nice!

The terminal relies on node-pty of course but it seems weird it is broken since you got it building, right? Maybe there is some other native module still failing.

Workspace search depends on the @vscode/ripgrep module which downloads the rg binary, maybe it is downloading one incompatible with FreeBSD (should be located at lib/vscode/node_modules/@vscode/ripgrep/bin/rg).