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

[bug] Watch mode does not watch. #1828

Closed
trusktr opened this issue Dec 29, 2017 · 39 comments
Closed

[bug] Watch mode does not watch. #1828

trusktr opened this issue Dec 29, 2017 · 39 comments

Comments

@trusktr
Copy link

trusktr commented Dec 29, 2017

I just upgraded to 0.53.0 and Rollup no longer even tries to watch anything. Instead, it exits back to the command line right after the first build as if I ran rollup without the --watch option. However, it does enter the alternate buffer while building, but then returns back to the main buffer when the first build finishes.

@trusktr trusktr changed the title [bug] Watch mode is borked. [bug] Watch mode does not watch. Dec 30, 2017
@trusktr
Copy link
Author

trusktr commented Dec 30, 2017

Changed to a more helpful title.

@ankeetmaini
Copy link
Contributor

Hi @trusktr , I tried running it and it worked fine for me. I updated your repo (infamous) to use latest version 0.53.1 and watch mode was watching the files.
rollup-test 1

@trusktr
Copy link
Author

trusktr commented Dec 30, 2017

Weird, I just updated to 0.53.1, and it just exits with error code 1 and no output:

trusktr+infamous git:master ❯ ./node_modules/.bin/rollup -c --watch

trusktr+infamous git:master ❯ echo $?
1

@trusktr
Copy link
Author

trusktr commented Dec 30, 2017

Alright, I deleted node_modules/rollup* and reinstalled, and now it works. This has happened to me several times now, not sure what's going on yet.

Only --watch mode fails on me, non-watch mode works fine.

Here's my reproduction branch: https://github.com/trusktr/infamous/tree/rollup-rollup-issue-1828

npm i
npm run build-global -- --watch
#or
./node_modules/.bin/rollup -c -w

both of those are exiting with error code 1 for me on that branch.

@ankeetmaini
Copy link
Contributor

I'm afraid this branch also works fine for me. :(. I couldn't reproduce it. I use VS Code. Could you delete all your node_modules, and npm cache and try again?

The watch mode runs just like the above gif I posted on rollup-rollup-issue-1828 branch too.

@ankeetmaini
Copy link
Contributor

Also, could you clone this and try to run it in watch mode?
https://github.com/ankeetmaini/rollup-watch-test and see if your system still crashes. This is a minimal watch setup.

@trusktr
Copy link
Author

trusktr commented Dec 30, 2017

It doesn't work for me with that minimal repo either!

This is what I get:

src ❯ git clone git@github.com:ankeetmaini/rollup-watch-test.git
Cloning into 'rollup-watch-test'...
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 9 (delta 1), reused 9 (delta 1), pack-reused 0
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (1/1), done.
Checking connectivity... done.

src ❯ cd rollup-watch-test

rollup-watch-test git:master ❯ npm i
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN The package rollup is included as both a dev and production dependency.

added 1 package in 45.741s

rollup-watch-test git:master ❯ npm run watch

> rollup-watch-test@1.0.0 watch /home/trusktr/Downloads/src/rollup-watch-test
> rollup -c -w

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rollup-watch-test@1.0.0 watch: `rollup -c -w`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rollup-watch-test@1.0.0 watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/trusktr/.npm/_logs/2017-12-30T21_31_52_952Z-debug.log

rollup-watch-test git:master ❯ cat /home/trusktr/.npm/_logs/2017-12-30T21_31_52_952Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'watch' ]
2 info using npm@5.6.0
3 info using node@v8.5.0
4 verbose run-script [ 'prewatch', 'watch', 'postwatch' ]
5 info lifecycle rollup-watch-test@1.0.0~prewatch: rollup-watch-test@1.0.0
6 info lifecycle rollup-watch-test@1.0.0~watch: rollup-watch-test@1.0.0
7 verbose lifecycle rollup-watch-test@1.0.0~watch: unsafe-perm in lifecycle true
8 verbose lifecycle rollup-watch-test@1.0.0~watch: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/trusktr/Downlo
ads/src/rollup-watch-test/node_modules/.bin:/home/linuxbrew/.linuxbrew/bin:/home/trusktr/go/bin:/home/linuxbrew/.linuxbrew/bin:/home/trusktr/go/bin:/
usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/trusktr/.local/bin:/home/trusktr/.gem/ruby/1.9.1/bin:/home/trusktr/.gem/ruby/2.2.0/bin:
/usr/local/bin:/home/trusktr/.vim/bundle/fzf/bin:/home/trusktr/.local/bin:/home/trusktr/.gem/ruby/1.9.1/bin:/home/trusktr/.gem/ruby/2.2.0/bin:/usr/lo
cal/bin
9 verbose lifecycle rollup-watch-test@1.0.0~watch: CWD: /home/trusktr/Downloads/src/rollup-watch-test
10 silly lifecycle rollup-watch-test@1.0.0~watch: Args: [ '-c', 'rollup -c -w' ]
11 silly lifecycle rollup-watch-test@1.0.0~watch: Returned: code: 1  signal: null
12 info lifecycle rollup-watch-test@1.0.0~watch: Failed to exec watch script
13 verbose stack Error: rollup-watch-test@1.0.0 watch: `rollup -c -w`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack     at emitTwo (events.js:125:13)
13 verbose stack     at EventEmitter.emit (events.js:213:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:125:13)
13 verbose stack     at ChildProcess.emit (events.js:213:7)
13 verbose stack     at maybeClose (internal/child_process.js:927:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
14 verbose pkgid rollup-watch-test@1.0.0
15 verbose cwd /home/trusktr/Downloads/src/rollup-watch-test
16 verbose Linux 3.18.0-16037-gf59ef0b48a68
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "watch"
18 verbose node v8.5.0
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error rollup-watch-test@1.0.0 watch: `rollup -c -w`
22 error Exit status 1
23 error Failed at the rollup-watch-test@1.0.0 watch script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

That line looks like this:

  proc.on('close', function (code, signal) {
    opts.log.silly('lifecycle', logid(pkg, stage), 'Returned: code:', code, ' signal:', signal)
    if (signal) {
      process.kill(process.pid, signal)
    } else if (code) {
      var er = new Error('Exit status ' + code) // <-- RIGHT HERE ------------------------------
      er.errno = code
    }
    procError(er)
  })

That's not a very helpful error!

@trusktr
Copy link
Author

trusktr commented Dec 30, 2017

I'm on npm 5.6.0 and node 8.5.0. What about you @ankeetmaini ? BTW, thanks for looking into this! Seems to be something up with my specific system?

I'm in Chrome OS, running Ubuntu 16.04.3 LTS (xenial) in a chroot set up with Crouton. So I'm basically in a "Linux" environment.

What other info can I provide?

@ankeetmaini
Copy link
Contributor

I'm running Node v7.7.3 and npm 4.1.2. I'll try to emulate your error by using the same versions. Although it should just work because tests run on

$ node --version
v8.9.3
$ npm --version
5.5.1

@aaron-harvey
Copy link

I believe I am experiencing a similar issue as well, but I've found that if I save multiple times in a row it usually updates.

VSCode
Arch 4.9 LTS
yarn 1.3.2
node 8.9.4
rollup 0.54.0

@Terverok
Copy link

I also have this irritating problem, whenever i make some change using vim nothing happens.
My vim configuration works without problems with webpack on other project.
My versions:
rollup 0.53.0
npm 5.4.2
node 8.8.0
vim 8.0
Mint 18.1 serena

@forestofrain
Copy link

Same issue here, where watch doesn't do anything when files in my include path changes. Docs show to use a watch config:

// rollup.config.js
export default {
  ...,
  watch: {
    include: 'src/**'
  }
};

Nothing happens, similar to the comments from others.

However, I was able to get it to work by passing in the paths to chokidar like the docs suggest

an Object of options that are passed through to chokidar.

// rollup.config.js
export default {
  ...,
  watch: {
    chokidar: {
        paths: 'src/**'
    }
  }
};

@trusktr
Copy link
Author

trusktr commented Feb 7, 2018

I switched back to Webpack, for now. Rebuilding was taking up too much time. Looking forward to it being fixed!

@trusktr
Copy link
Author

trusktr commented Feb 7, 2018

Oh, wait, I don't think tried that chokidar option. I'll give that a go...

@mspanish
Copy link

even with chokidar as an option, on Windows 10 with rollup 0.57.1 nothing is watched.

@laughinghan
Copy link

This is definitely a bug with rollup. Installing chokidar-cli and doing chokidar <files> -c 'rollup -c' works fine, but watch: { include: <files>, chokidar: true } in the rollup.config.js doesn't work at all.

@burningTyger
Copy link

works here on Linux when is set paths on chokidar. However, it doesn't rebuilt when I change an asset. Not sure if that is a feature or a bug.

@jrabbit
Copy link

jrabbit commented Jun 1, 2018

Does it have a TTY? i just ran into this w/ docker-compose which drops tty stuff by default

@ghost
Copy link

ghost commented Jun 1, 2018

I think I'm experiencing something similar. Half of the time rollup-watch works fine, the other half I have to repeatedly save the file to make it compile (5~20 times).

Windows 10
VSCode
Node 9.5.0
NPM 5.6.0
Rollup 0.59.4

plugins: [
  resolve(),
  uglify(),
  buble(),
  commonjs()
]

@mourner
Copy link
Contributor

mourner commented Jun 11, 2018

I think I figured out the original issue, and a workaround: rollup -w used to run the watch mode on the default config, but now it just exists without a warning. However rollup -cw works.

@guybedford
Copy link
Contributor

@mourner thanks for the update... do you think it would be worth reverting to the former behaviour? Would you be interested in a PR here at all?

@mourner
Copy link
Contributor

mourner commented Jun 11, 2018

@guybedford I think it should be either reverted, or supplied with a helpful error message, because it's really confusing when you're upgrading from an older version and watch mode just stops working without any indication of what's exactly wrong. I'd happily let someone else do a PR though — might be a good "first PR" issue.

@mourner
Copy link
Contributor

mourner commented Jun 11, 2018

Looks like it might be a different issue than the one reported by the original poster, because in their example the command is -c --watch, which should work.

@BobbyBabes
Copy link

Worth checking.

If you're on Linux, check that your watcher is not running out of file handles :
"Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC)
and Increasing the amount of inotify watchers.

On Linux and OS X if you delete a watched path/dir/file, and then recreate it, the deleted inode will continue to be watched by fs.watch() : The watch will emit an event for the delete but will continue watching the original inode.

@waynebaylor
Copy link

i had similar problems running rollup -c -w inside docker. i tried setting include and paths, which didn't fix it. finally tried using polling (same as CRA tells you to do inside a VM) and that worked:

watch: {
  chokidar: {
    usePolling: true
  }
}

@DjebbZ
Copy link

DjebbZ commented May 2, 2019

I confirm that adding chokidar.usePolling: true solved the problem for me. Every change is caught by rollup now.
Linux Kernel 5.0.9
node v11.14.0
npm 6.9.0
rollup 1.10.1
chokidar 3.0.0

@brewster1134
Copy link

i have tried a variety of different variations, but nothing seems to work except for js & sass files. specifically i have an html file that i am using the copy plugin to move from src to dist. i assume js & sass files work, because the js file is used ininput, and the path to the sass files are defined in the sass plugin config, and are therefore "registered" to be watched. any other file type is not being watched, and i have tried every combination of watch.include: 'src/**', watch.chokidar.paths: src/**', watch.chokidar.usePolling: true. for the chokidar config, i have even tried using pathandpaths`, as well as a string, and an array of strings, just to cover every option.

did you who seemed to solve the issue, solve it for any file type?

@kasperstorgaard
Copy link

I had an issue with codesplitting and entryFileNames option:
There is a gotcha, that you cannot use [hash] naming in entryFileNames, like this: entryFileNames: [name].[hash].js.
If you do that, then the watch will trigger correctly, but not actually be picked up when you reload the page (since the reference in the html is now pointing to an old entry file, with a different hash)

The solution is to do something like this in your rollup.config.js:

const isWatch = !process.env.ROLLUP_WATCH;
...
entryFileNames: `${isWatch ? '[name]' : '[name].[hash]'}.js`,

@shellscape
Copy link
Contributor

Hey folks. This is a saved-form message, but rest assured we mean every word. The Rollup team is attempting to clean up the Issues backlog in the hopes that the active and still-needed, still-relevant issues bubble up to the surface. With that, we're closing issues that have been open for an eon or two, and have gone stale like pirate hard-tack without activity.

We really appreciate the folks have taken the time to open and comment on this issue. Please don't confuse this closure with us not caring or dismissing your issue, feature request, discussion, or report. The issue will still be here, just in a closed state. If the issue pertains to a bug, please re-test for the bug on the latest version of Rollup and if present, please tag @shellscape and request a re-open, and we'll be happy to oblige.

@tvvignesh
Copy link

@brewster1134 Same issue for me. It watches and works for every type of file except for html files. Not sure why. Stuck last 3 hours with this :-(

@saurabhnemade
Copy link

I am also facing same issue. so far nothing worked.

@saurabhnemade
Copy link

I ended up adding:

    "build": "rollup -c",
    "build-watch": "rollup -c -w",
    "build-watch2": "chokidar src/**/* -c 'yarn build'",

this works pretty slick on Mac OS.

@caiodv
Copy link

caiodv commented Aug 18, 2020

Just in case anyone is facing this issue while using WSL2 on Windows, and your files are under the windows filesystem, move them to the distro's filesystem and it shall work.

@dgellow
Copy link

dgellow commented Oct 21, 2020

@caiodv Thanks, doing everything from WSL2 works for me. Though I'm not sure why the issue still exists on Windows as inotify is supposed to be supported by Docker Desktop for Windows since "Docker Desktop Community 2.2.0.0 / 2020-01-21".

Docker Desktop now supports inotify events on shared filesystems.

Source: https://docs.docker.com/docker-for-windows/release-notes/#bug-fixes-and-minor-changes-8

@AlbertMarashi
Copy link

Using WSL 2 with docker containers

Deleting my node_modules in my project, and deleting rollup in my C:\Program Files\nodejs\node_modules global folder and force reinstalling with npm i -g rollup --force worked for me.

Make sure to install your code in a linux filesystem instead of using WSL file-sharing (eg: put your files in an Ubuntu filesystem, and use VSCode Remote-WSL extension)

@dongyuwei
Copy link

Same issue here, where watch doesn't do anything when files in my include path changes. Docs show to use a watch config:

// rollup.config.js
export default {
  ...,
  watch: {
    include: 'src/**'
  }
};

Nothing happens, similar to the comments from others.

However, I was able to get it to work by passing in the paths to chokidar like the docs suggest

an Object of options that are passed through to chokidar.

// rollup.config.js
export default {
  ...,
  watch: {
    chokidar: {
        paths: 'src/**'
    }
  }
};

This works for our project. And you need to install chokidar manually: npm install --save-dev chokidar

@Lionad-Morotar
Copy link

Hi, any progress on this issue so far? I'm experiencing the same distress, woohoo.

Lionad-Morotar added a commit to Lionad-Morotar/read-source-code that referenced this issue Jun 16, 2022
@aminnairi
Copy link

For whoever is desperate and see this comment, if this issue is not re-opened and addressed, here is a configuration example for the following architecture of files (using React for server-side rendering of lazy routes).

.
├── client.js
├── components
│   ├── app.js
│   ├── header.js
│   └── loader.js
├── controllers
│   └── static.js
├── package.json
├── package-lock.json
├── pages
│   ├── home.js
│   └── not-found.js
├── README.md
├── rollup.config.js
├── server.js
├── static
│   └── robots.txt
└── utils
    └── stream.js
import {resolve} from "path";

export default [
  {
    input: resolve("client.js"),
    output: {
      dir: resolve("build", "client"),
      format: "esm"
    },
    watch: {
      include: resolve("**", "*.js"),
      exclude: resolve("node_modules", "**", "*.js"),
      chokidar: {
        usePolling: true
      }
    }
  },
  {
    input: resolve("server.js"),
    output: {
      file: resolve("build", "server", "server.js"),
      format: "esm",
      inlineDynamicImports: true
    },
    watch: {
      include: resolve("**", "*.js"),
      exclude: resolve("node_modules", "**", "*.js"),
      chokidar: {
        usePolling: true
      }
    }
  }
];

@signal-intrusion
Copy link

For my issue, watch works exactly once, meaning that it rollup recompiles the first time I save a file, but never again after that. I'm pretty much stuck with using nodemon and running the build task over and over again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests