svrxjs/svrx

Using svrx from API: fsevents.watch is not a function

Closed this issue · 2 comments

imyzf commented

Describe the bug
Using svrx from API, it will throw an error. But no problem from CLI.

To Reproduce

const Svrx = require('@svrx/svrx')

const server = new Svrx()
server.start()

Screenshots
API:
image

CLI:
image

Desktop (please complete the following information):

  • OS: macOS 10.14.6
  • node v11.6.0

Cannot reproduce now, feel free to reopen the issue if there's still a problem

This bug is macOS only.

fsevents.watch is a new func in fsevents@2. And svrx depends on chokidar@3, and fsevents@2 is an optional dependency of chokidar@3.

Unfortunately, svrx uses shrinkwrap to lock all dependencies, which will drop all optional dependencies. That means svrx won't install fsevents at all.

chokidar will check if fsevents exist before use, which will prevent 'not found fsevents error':

let fsevents;
try {
  fsevents = require('fsevents');
} catch (error) {
  if (process.env.CHOKIDAR_PRINT_FSEVENTS_REQUIRE_ERROR) console.error(error);
}

However, if your project has fsevents as a dependency and is not a version of 2, errors like 'fsevents.watch is not a function' might occur.

The workaround is add fsevents@2 as a dependency in your own project.