mikaelbr / node-notifier

A Node.js module for sending notifications on native Mac, Windows and Linux (or Growl as fallback)
MIT License
5.73k stars 322 forks source link

WSL 2 error when running NPM script #357

Open seank842 opened 3 years ago

seank842 commented 3 years ago

System information

OS: Windows 10 19042.685 running Ubuntu 20.04 in WSL2

Getting an error when running NPM run development:

node:events:353
      throw er; // Unhandled 'error' event
      ^

Error: listen ENOTSUP: operation not supported on socket \\.\pipe\notifierPipe-e659d739-c36e-4ddf-af48-3a3ff45990f5
    at Server.setupListenHandle [as _listen2] (node:net:1278:21)
    at listenInCluster (node:net:1343:12)
    at Server.listen (node:net:1440:5)
    at /mnt/c/Users/seank/Source/Repos/[Redacted]/node_modules/node-notifier/lib/utils.js:566:21
    at new Promise (<anonymous>)
    at Object.module.exports.createNamedPipe (/mnt/c/Users/seank/Source/Repos/[Redacted]/node_modules/node-notifier/lib/utils.js:557:10)
    at WindowsToaster.notifyRaw (/mnt/c/Users/seank/Source/Repos/[Redacted]/node_modules/node-notifier/notifiers/toaster.js:133:9)
    at WebpackNotifierPlugin.compilationDone (/mnt/c/Users/seank/Source/Repos/[Redacted]/node_modules/webpack-notifier/index.js:129:14)
    at _next1 (eval at create (/mnt/c/Users/seank/Source/Repos/[Redacted]/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at eval (eval at create (/mnt/c/Users/seank/Source/Repos/[Redacted]/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:50:1)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1322:8)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  code: 'ENOTSUP',
  errno: -95,
  syscall: 'listen',
  address: '\\\\.\\pipe\\notifierPipe-e659d739-c36e-4ddf-af48-3a3ff45990f5',
  port: -1
}
npm ERR! code 1
npm ERR! path /mnt/c/Users/seank/Source/Repos/[Redacted]
npm ERR! command failed
npm ERR! command sh -c webpack --progress --config=/mnt/c/Users/seank/Source/Repos/[Redacted]/node_modules/laravel-mix/setup/webpack.config.js

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/seank/.npm/_logs/2021-01-07T19_01_25_526Z-debug.log
npm ERR! code 1
npm ERR! path /mnt/c/Users/seank/Source/Repos/[Redacted]
npm ERR! command failed
npm ERR! command sh -c mix

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/seank/.npm/_logs/2021-01-07T19_01_25_553Z-debug.log

Workaround

In file file node_modules/node-notifier/lib/utilis.js comment out lines 554-570 and place the following code bellow:

module.exports.createNamedPipe = (server) => {
  const buf = Buffer.alloc(BUFFER_SIZE);

  return new Promise((resolve) => {   
     resolve(buf);
  });
};

Workaround received from https://www.petitmonte.com/windows/wsl2-pipe-notifierpipe.html

After workaround is in place notification fire as expected on windows 10 and no error is given from node.

yonicsurny commented 3 years ago

I have the same issue and can confirm that the workaround fixed it.

In my case I am using laravel-mix and the code was inside webpack-notifier/mode_modules/node-notifier/utils.js