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

nuxi dev fails with Error: Cannot find module fsevents #11863

Closed
pimlie opened this issue Oct 1, 2021 · 6 comments
Closed

nuxi dev fails with Error: Cannot find module fsevents #11863

pimlie opened this issue Oct 1, 2021 · 6 comments

Comments

@pimlie
Copy link

pimlie commented Oct 1, 2021

Environment

------------------------------
- Operating System: `Linux`
- Node Version:     `v14.16.0`
- Nuxt Version:     `2.15.8`
- Package Manager:  `Yarn`
- Bundler:          `Webpack`
- User Config:      `-`
- Runtime Modules:  `-`
- Build Modules:    `-`
------------------------------

Describe the bug and expected behavior

Running yarn nuxi dev immediately fails with this error

Steps to reproduce

On a Linux system:

  1. Run yarn add @nuxt/bridge-edge
  2. Run yarn nuxi dev src

Additional context

Nuxt CLI v0.10.0-27217109.e13baf9
[error] Error: Cannot find module 'fsevents'
Require stack:
- ~/project/node_modules/nuxi/dist/chunks/dev.cjs
- ~/project/node_modules/nuxi/dist/chunks/index.cjs
- ~/project/node_modules/nuxi/dist/index.cjs
- ~/project/node_modules/nuxi/bin/nuxi.cjs
Copy link
Member

Two comments, unrelated to the issue.

First, for the moment you should add @nuxt/bridge like this:

{
  "devDependencies": {
    "@nuxt/bridge": "npm:@nuxt/bridge-edge@0.0.0-27217109.e13baf9"
  }
}

Second, you should just be able to run nuxi dev or nuxi dev <rootDir> (where rootDir is the folder with your nuxt.config.js).

Copy link
Member

danielroe commented Oct 1, 2021

With regard to this issue, the issue is that bundling chokidar is leaving this code in the nuxi bundle:

const require$$3 = require('fsevents');
// ...

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

(fsevents is only available on MacOS.) The issue is that require is being extracted from the location where chokidar is trying to handle errors with import (see paulmillr/chokidar#828 for context).

We can 'solve' by adding 'chokidar' to dependency list but this is likely not a good solution - we may need some rollup magic - or bug fixing. cc: @pi0.

@pimlie
Copy link
Author

pimlie commented Oct 2, 2021

@danielroe fyi, I deliberately added nuxt/bridge as a production dependency. When you are building for a Lambda, Netlify Function, or Edge handler then you don't have any use for production dependencies in the traditional sense.

So instead it's recommended to:

  • add any Nuxt / build dependency as a production dependency ("dependencies")
  • add any dependency related to testing as a development dependency ("devDependencies")

Eg this way if you are building on Netlify you can run yarn install --frozen-lockfile --production --ignore-optional to minimize deploy time as you don't have to install massive dependencies like Playwright that you only need when running tests on Github Actions or CircleCI

@pi0 pi0 added the cli label Oct 2, 2021
@pi0
Copy link
Member

pi0 commented Oct 2, 2021

Hi, @pimlie thanks for reporting the issue.

Actually, you are facing this issue because of using the new cli, not the bridge module (nor nitro). You can keep using nuxt dev command. Check bridge migration too.

Also normally with nuxt 3 / bridge, you should put all dependencies to devDependencies since final .output/ directory is standalone. (unless you have a usecase like mentioned above to split testing deps)

Refarding the issue: Nuxi cli embeds all dependencies so that global installation is as fast as possible but as @danielroe mentioned, rollup used to bundle nuxi/dist moves try/catch deps to top level. This issue is solved in unbuild@0.5.6 by setting ignoreTryCatch flag. Will try to update and see if solves issue.

@pimlie
Copy link
Author

pimlie commented Oct 4, 2021

@pi0 If users are meant not to be using nuxi when using v2 + bridge then it might help to add a nuxt version check in nuxi and inform users about that? Cause I certainly wont be the last person not really reading the docs and just try something ;)

@pi0
Copy link
Member

pi0 commented Oct 4, 2021

Issue is solved i tried on ubuntu since in nuxi >= 0.10.0-27220306.0a9342c we preserve try/catch

image


BTW actually nuxi is meant to support Nuxt 2 / bridge and at some point also advised to. Just at the moment, it is not stable so neither advised nor prohibited by the docs but indeed if it until going public it is still having known issues we might need to add a warning about unstability and that bridge users can keep using nuxt CLI.

@pi0 pi0 closed this as completed Oct 4, 2021
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants