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

Cannot run recent versions of Node.js in Vagrant boxes #13263

Closed
BadIdeaException opened this issue Sep 20, 2023 · 16 comments
Closed

Cannot run recent versions of Node.js in Vagrant boxes #13263

BadIdeaException opened this issue Sep 20, 2023 · 16 comments

Comments

@BadIdeaException
Copy link

Recent versions of Node.js (v18.18 and newer) fail with an ENOTSUP error when running NPM commands inside a Vagrant box. I have tried this with both versions from the Nodesource repos and directly from nodejs.org.

This error does not occur with Node.js v17.x.

Debug output

For debug output of vagrant up see vagrant.log.

Error log of npm start:

0 verbose cli /usr/local/lib/nodejs/node-v18.18.0-linux-x64/bin/node /usr/local/lib/nodejs/node-v18.18.0-linux-x64/bin/npm
1 info using npm@9.8.1
2 info using node@v18.18.0
3 timing npm:load:whichnode Completed in 16ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:/usr/local/lib/nodejs/node-v18.18.0-linux-x64/lib/node_modules/npm/npmrc Completed in 0ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:/vagrant/.npmrc Completed in 0ms
10 timing config:load:project Completed in 1ms
11 timing config:load:file:/home/vagrant/.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:/usr/local/lib/nodejs/node-v18.18.0-linux-x64/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:setEnvs Completed in 1ms
16 timing config:load Completed in 10ms
17 timing npm:load:configload Completed in 11ms
18 timing config:load:flatten Completed in 4ms
19 timing npm:load:mkdirpcache Completed in 0ms
20 timing npm:load:mkdirplogs Completed in 6ms
21 verbose title npm start
22 verbose argv "start"
23 timing npm:load:setTitle Completed in 1ms
24 timing npm:load:display Completed in 1ms
25 verbose logfile logs-max:10 dir:/home/vagrant/.npm/_logs/2023-09-20T09_14_15_571Z-
26 verbose logfile /home/vagrant/.npm/_logs/2023-09-20T09_14_15_571Z-debug-0.log
27 timing npm:load:logFile Completed in 37ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 129ms
31 timing command:run-script Completed in 15ms
32 timing command:start Completed in 93ms
33 verbose stack Error: Could not read package.json: Error: ENOTSUP: operation not supported on socket, read
34 verbose cwd /vagrant
35 verbose Linux 5.15.0-79-generic
36 verbose node v18.18.0
37 verbose npm  v9.8.1
38 error code ENOTSUP
39 error syscall read
40 error errno -95
41 error Could not read package.json: Error: ENOTSUP: operation not supported on socket, read
42 verbose exit -95
43 timing npm Completed in 848ms
44 verbose code -95
45 error A complete log of this run can be found in: /home/vagrant/.npm/_logs/2023-09-20T09_14_15_571Z-debug-0.log

Expected behavior

npm start should run the script.

Actual behavior

npm ERR! code ENOTSUP
npm ERR! syscall read
npm ERR! errno -95
npm ERR! Could not read package.json: Error: ENOTSUP: operation not supported on socket, read

npm ERR! A complete log of this run can be found in: /home/vagrant/.npm/_logs/2023-09-20T08_13_54_770Z-debug-0.log

Other operations also result in socket errors, i.e. npm install mocha:

npm WARN tar TAR_ENTRY_ERROR ENOTSUP: operation not supported on socket, write

Reproduction information

Vagrant version

Vagrant 2.3.7

Host operating system

Ubuntu Jammy

Linux XXXXXXXXXX 6.2.0-31-generic #31~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Aug 16 13:45:26 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Guest operating system

Tried with ubuntu/jammy64 and ubuntu/lunar64

Steps to reproduce

  1. Place the below Vagrantfile, package.json and main.js in a folder and cd to it
  2. vagrant up then vagrant ssh
  3. cd /vagrant
  4. npm start

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/jammy64"
  # Install Node.JS
  config.vm.provision "shell", name: "Install Node.JS", env: { "NODE_MAJOR" => "18" }, inline: <<-SHELL
    # Install necessary packages for downloading and verifying new repository information
    apt-get install -y ca-certificates curl gnupg
    # Create a directory for the new repository's keyring, if it doesn't exist
    mkdir -p /etc/apt/keyrings
    # Download the new repository's GPG key and save it in the keyring directory
    curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
    # Add the new repository's source list with its GPG key for package verification
    echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
    # Update local package index to recognize the new repository
    sudo apt-get update
    # Install Node.js from the new repository
    sudo apt-get install -y nodejs
  SHELL
end

package.json:

{
  "scripts": {
    "start": "node main.js"
  }
}

main.js:

console.log('Hello world');
@ViniciusGularte
Copy link

ViniciusGularte commented Sep 20, 2023

Facing the same ENOTSUP error with Node.js v18.18 in Vagrant. It works fine with v17.x or 16. Watching this thread for solutions.

@BadIdeaException
Copy link
Author

Just tried this on another computer, and I am seeing the same behavior there, too.

@chrisroberts
Copy link
Member

@BadIdeaException Are you still encountering this behavior? I used the provided Vagrantfile and everything worked as expected. Would you mind verifying the error still occurs for you on the latest ubuntu/jammy64 box release?

Thanks!

@BadIdeaException
Copy link
Author

I'm still seeing the same thing. Guest OS is now:

uname -a:

Linux ubuntu-jammy 5.15.0-84-generic #93-Ubuntu SMP Tue Sep 5 17:16:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

vagrant box list

...
ubuntu/jammy64            (virtualbox, 20230929.0.0)
...

@sunxyw
Copy link

sunxyw commented Nov 23, 2023

same problem here, any fix?

EDIT: The problem seems to be related to virtualbox, after switching to hyperv I don't have this problem.

EDIT2: Changing the synced folder type to "smb" seems fix the issue, https://developer.hashicorp.com/vagrant/docs/synced-folders/smb

@dugwood
Copy link

dugwood commented Nov 23, 2023

@sunxyw I've got the issue too. It's only when npm is installed in a mounted directory (shared directory). So I've moved my npm install directory to a non-shared directory, which works. Not great, but does the trick too.

[EDIT] I'm on Virtualbox 7.0, but the issue seems to be on both Vagrant and Virtualbox.

@ceztko
Copy link

ceztko commented Nov 27, 2023

Same error but just on Virtualbox with a much simpler code residing on a shared directory, so probably same as @dugwood. The problem seems to be specifically related on the node ESModule loader. In fact, the same simple code but running as CommonJS doesn't manifest the issue. Possibly something that node upstream should be informed of.

@AppSecAmael
Copy link

Hello, same error here with Kali / Virtualbox / Vagrant mounted folder

@owenallenaz
Copy link

owenallenaz commented Jan 16, 2024

Ran into this issue, and was able to switch to type: "smb" for the synced_folder and it resolved the issue. I haven't been on it long enough to determine if that new type is going to open up it's own problems, but for now stuff appears to be working.

Edit: Had to revert because the smb was simply too slow to be usable... back to trying to find answers.

@AppSecAmael
Copy link

Hello, how can we help on this issue ? Even a simple "npm install" fails with ENOTSUP when launched on a vagrant fileshare (fstype : vboxfs).

─$ npm install        
npm ERR! code ENOTSUP
npm ERR! syscall write
npm ERR! errno -95
npm ERR! ENOTSUP: operation not supported on socket, write


Debug log :

─$ cat /home/[REDACTED]/.npm/_logs/2024-01-18T07_16_55_123Z-debug-0.log 
0 verbose cli /usr/bin/node /usr/bin/npm
1 info using npm@9.2.0
2 info using node@v18.19.0
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 3ms
6 timing config:load:builtin Completed in 3ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:/vagrant/host-workspace/[REDACTED]/.npmrc Completed in 0ms
10 timing config:load:project Completed in 5ms
11 timing config:load:file:/home/[REDACTED]/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:setEnvs Completed in 1ms
16 timing config:load Completed in 12ms
17 timing npm:load:configload Completed in 12ms
18 timing npm:load:mkdirpcache Completed in 4ms
19 timing npm:load:mkdirplogs Completed in 0ms
20 verbose title npm install
21 verbose argv "install"
22 timing npm:load:setTitle Completed in 1ms
23 timing config:load:flatten Completed in 3ms
24 timing npm:load:display Completed in 4ms
25 verbose logfile logs-max:10 dir:/home/[REDACTED]/.npm/_logs/2024-01-18T07_16_55_123Z-
26 verbose logfile /home/[REDACTED]/.npm/_logs/2024-01-18T07_16_55_123Z-debug-0.log
27 timing npm:load:logFile Completed in 7ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 28ms
31 silly logfile start cleaning logs, removing 1 files
32 timing config:load:flatten Completed in 0ms
33 timing arborist:ctor Completed in 0ms
34 silly logfile done cleaning log files
35 timing arborist:ctor Completed in 0ms
36 timing idealTree:init Completed in 11ms
37 timing idealTree:userRequests Completed in 0ms
38 silly idealTree buildDeps
39 timing idealTree:#root Completed in 0ms
40 timing idealTree:buildDeps Completed in 1ms
41 timing idealTree:fixDepFlags Completed in 0ms
42 timing idealTree Completed in 13ms
43 timing reify:loadTrees Completed in 14ms
44 timing reify:diffTrees Completed in 0ms
45 silly reify moves {}
46 timing reify:retireShallow Completed in 1ms
47 timing reify:createSparse Completed in 0ms
48 timing reify:loadBundles Completed in 0ms
49 timing reify:unpack Completed in 0ms
50 timing reify:unretire Completed in 0ms
51 timing build:queue Completed in 0ms
52 timing build:deps Completed in 1ms
53 timing build Completed in 1ms
54 timing reify:build Completed in 1ms
55 timing reify:trash Completed in 0ms
56 timing command:install Completed in 26ms
57 verbose stack Error: ENOTSUP: operation not supported on socket, write
58 verbose cwd /vagrant/host-workspace/[REDACTED]
59 verbose Linux 6.5.0-kali3-amd64
60 verbose node v18.19.0
61 verbose npm  v9.2.0
62 error code ENOTSUP
63 error syscall write
64 error errno -95
65 error ENOTSUP: operation not supported on socket, write
66 verbose exit -95
67 timing npm Completed in 71ms
68 verbose unfinished npm timer reify 1705562215167
69 verbose unfinished npm timer reify:save 1705562215187
70 verbose code -95
71 error A complete log of this run can be found in:
71 error     /home/[REDACTED]/.npm/_logs/2024-01-18T07_16_55_123Z-debug-0.log

@ceztko
Copy link

ceztko commented Jan 18, 2024

I'm stopping notifications on this since I have nothing in production that makes use of this setup but if anyone of you is really serious about seeing this fixed to the root cause, then should create an issue on node doing some further research and reporting these discoveries.

@AppSecAmael
Copy link

Done, I guess you can close this issue as it does not seem to be vagrant specific : the underlying filesystem's type is vboxfs.

@BadIdeaException
Copy link
Author

Closing this in favor of upstream issue nodejs/node#50876

@abhishek-ejam
Copy link

I can also confirm that below vagrant/virtualbox config is also affected by this bug:
Virtualbox: 6.1
Vagrant box: bento/ubuntu-22.04 (>=202309.08.0)

@hiAndrewQuinn
Copy link

hiAndrewQuinn commented Mar 3, 2024

Confirming this still happens, although it's a Node issue, not a Laravel issue.

I'm on Ubuntu 23.10 as my baremetal machine, using VirtualBox as a Vagrant provider for Homestead. On the shared folder code/,

composer create-project --prefer-dist laravel/laravel code/
cd code/
composer require laravel/breeze --dev

works fine, but

php artisan breeze:install

does not. Instead it leads to

 ┌ Which Breeze stack would you like to install? ───────────────┐
 │ Blade with Alpine                                            │
 └──────────────────────────────────────────────────────────────┘

 ┌ Would you like dark mode support? ───────────────────────────┐
 │ Yes                                                          │
 └──────────────────────────────────────────────────────────────┘

 ┌ Which testing framework do you prefer? ──────────────────────┐
 │ PHPUnit                                                      │
 └──────────────────────────────────────────────────────────────┘

   INFO  Installing and building Node dependencies.  

npm ERR! code ENOTSUP
npm ERR! syscall write
npm ERR! errno -95
npm ERR! ENOTSUP: operation not supported on socket, write

npm ERR! A complete log of this run can be found in: /home/vagrant/.npm/_logs/2024-03-03T11_34_39_227Z-debug-0.log


   INFO  Breeze scaffolding installed successfully.  

Doing all of this on a non-shared testdir/ works fine, but I can't move everything in testdir/ to code/, which is annoying.

Gonna try setting up a QEMU provider to see if that works better. EDIT: QEMU is not supported by Homestead (fair!). API only and HTMX it'll have to be!

@AppSecAmael
Copy link

This issue is closed in favor of upstream issue : nodejs/node#50876

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants