question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

brunch watch --server on infinite loop

See original GitHub issue

Description

Using rm -rf public/ && brunch watch --server command leads to infinite loop, when updating from 2.8 to 2.9.

Expected behavior

Build the project, and only rebuild when a change occur in any file.

Actual behavior

Infinite loop on build watch.

Environment

  1. Brunch: 2.9.1
  2. Node: 6.4.0
  3. NPM: 3.10.3
  4. Operating system: Ubuntu 16.04 LTS

package.json contents

{
  "name": "your-app",
  "description": "Description",
  "author": "Your Name",
  "version": "0.0.1",
  "repository": {
    "type": "git",
    "url": ""
  },
  "scripts": {
    "install-deps": "bash install-deps.sh",
    "start": "rm -rf public/ && brunch watch --server",
    "install-storybook": "npm install @kadira/storybook --registry=https://registry.npmjs.org",
    "test": "mocha --compilers js:babel-core/register \"./app/**/*.spec.js\"",
    "coverage": "nyc npm test",
    "test:watch": "mocha --watch --compilers js:babel-core/register \"./app/**/*.spec.js\"",
    "build": "rm -rf public/ && brunch build --production",
    "storybook": "start-storybook -p 4444 -s public",
    "postinstall": "cp -R app/assets/ public/"
  },
  "dependencies": {
    "assert": "^1.4.1",
    "assetsmanager-brunch": "^1.8.1",
    "auto-reload-brunch": "^2.7.0",
    "axios": "^0.13.1",
    "babel-eslint": "^6.1.2",
    "babel-plugin-istanbul": "^2.0.1",
    "babel-plugin-ramda": "^1.1.5",
    "babel-plugin-syntax-object-rest-spread": "^6.13.0",
    "babel-preset-es2015": "~6.3.13",
    "babel-preset-react": "~6.3.13",
    "babel-preset-stage-0": "^6.5.0",
    "babel-preset-stage-2": "^6.13.0",
    "babel6-brunch": "^7.0.0",
    "brunch": "2.8.2",
    "brunch-static": "^1.1.1",
    "chai": "^3.5.0",
    "chai-enzyme": "^0.5.1",
    "chalk": "^1.1.3",
    "classnames": "^2.2.5",
    "clean-css-brunch": "^2.0.0",
    "css-brunch": "^2.0.0",
    "deep-assign": "^2.0.0",
    "digest-brunch": "^1.5.1",
    "enzyme": "^2.4.1",
    "eslint": "^3.3.1",
    "feather": "1.3.3",
    "filesize": "^3.3.0",
    "globule": "^1.0.0",
    "gzip-size": "^3.0.0",
    "html-brunch-static": "^1.3.1",
    "istanbul": "^0.4.5",
    "javascript-brunch": "^2.0.0",
    "js-cookie": "^2.1.2",
    "mocha": "^3.0.1",
    "mocha-bamboo-reporter": "^1.1.1",
    "mocha-standard": "^1.0.0",
    "nyc": "^8.2.0-candidate1",
    "pleeease-brunch": "^3.0.0",
    "ramda": "^0.22.1",
    "react": "^15.3.0",
    "react-addons-css-transition-group": "^15.3.2",
    "react-addons-test-utils": "^15.3.1",
    "react-dom": "^15.3.0",
    "react-lazy-load": "^3.0.10",
    "react-maskedinput": "^3.2.4",
    "react-modal2": "^3.1.0",
    "react-redux": "^4.4.5",
    "redux": "^3.5.2",
    "redux-analytics": "^0.3.0",
    "redux-logger": "^2.6.1",
    "redux-mock-store": "^1.1.2",
    "redux-thunk": "^2.1.0",
    "replace": "^0.3.0",
    "sass-brunch": "^2.6.3",
    "sinon": "^1.17.5",
    "standard": "^8.1.0",
    "svg-extractor": "^0.5.18",
    "the-cage": "^1.6.4",
    "theme": "^2.0.0-beta.16",
    "uglify-js-brunch": "^2.0.0"
  },
  "optionalDependencies": {
    "@types/react": "^0.14.39",
    "@types/assert": "0.0.29",
    "@types/axios": "^0.9.32",
    "@types/chai": "^3.4.34",
    "@types/chalk": "^0.4.30",
    "@types/js-cookie": "^2.0.28",
    "@types/mocha": "^2.2.32",
    "@types/node": "^6.0.45",
    "@types/ramda": "0.0.2",
    "@types/react-dom": "^0.14.17",
    "@types/redux": "^3.6.31",
    "@types/redux-logger": "^2.6.32",
    "@types/redux-thunk": "^2.1.31",
    "@kadira/storybook": "^2.3.0"
  },
  "engines": {
    "node": ">=6"
  },
  "main": "brunch-config.js",
  "license": "ISC",
  "nyc": {
    "require": [
      "babel-register",
      "mocha"
    ],
    "all": false,
    "sourceMap": true,
    "instrument": true,
    "include": [
      "app/**/*.js"
    ],
    "exclude": [
      "app/**/*.spec.js",
      "app/**/*.story.js",
      "app/*.js",
      "public/*.*",
      "app/*.handlebars",
      "app/**/*-container.js"
    ]
  },
  "standard": {
    "parser": "babel-eslint",
    "globals": [
      "describe",
      "it",
      "CustomEvent"
    ]
  }
}

brunch config contents

const fs = require('fs')
const fileSize = require('filesize')
const gzipSize = require('gzip-size')
const chalk = require('chalk')

const configGenerator = require('./config/config-generator')
const localeGenerator = require('./locale/locale-generator')

// this file generates the variables used in the build
const brunchEnv = require('./brunch-env')
const { brand, env, brandHeader, faviconPath, svgStore } = brunchEnv

function logGzipSize (path) {
  const fileContents = fs.readFileSync(path)
  console.log(`> ${chalk.cyan(path)}: ${fileSize(gzipSize.sync(fileContents))}`)
}

exports.config = {
  files: {
    javascripts: { joinTo: 'basket.js' },

    stylesheets: {
      joinTo: {
        'basket.css': `app/styles/basket.${brand}.scss`,
        'theme.css': /^node_modules/
      }
    }
  },

  modules: {
    autoRequire: { 'basket.js': ['initialize'] }
  },

  conventions: {
    ignored: [/spec\.js$/, /story\.js$/]
  },

  npm: {
    styles: { theme: [`dist/${brand}/stylesheets/theme.css`] }
  },

  plugins: {
    static: {
      processors: [
        require('html-brunch-static')({
          handlebars: {
            enableProcessor: true
          },
          defaultContext: brunchEnv
        })
      ]
    },
    assetsmanager: {
      copyTo: {
        '': [faviconPath]
      }
    },
    pleeease: {
      autoprefixer: {
        browsers: ['last 5 versions', 'not ie <= 8']
      },
      mqpacker: true
    }
  },

  overrides: {
    production: {
      files: {
        javascripts: {
          entryPoints: { 'app/initialize.js': 'basket.js' }
        }
      }
    }
  },

  hooks: {
    preCompile: (end) => {

       // these functions write two different files in the 'app' folder

      Promise.all([
        configGenerator(env, brand),
        localeGenerator(brand)
      ]).then(end)
    },
    onCompile: () => {
      // logs final gzipped file sizes
      const publicFolder = 'public/'
      const publicFiles = fs.readdirSync(publicFolder)

      console.log(chalk.gray('\nFinal gzipped file sizes:\n'))
      publicFiles.forEach(file => logGzipSize(publicFolder + file))

      console.log(chalk.gray('\n----------\n'))
      // write static svg file to use in storybook only in development
      if (env === 'development') {
        fs.writeFile('public/svg_store.min.svg', svgStore)
        fs.writeFile('public/header.html', brandHeader)
      }
    }
  }
}

Additional information

Also, I was already having an issue in version 2.8.2: from time to time, the watch would not work, and the application would not find some modules. I have to restart the watcher manually from time to time.

What more information could I give to you to help with the diagnosis?

Thank you in advance!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
solisoftcommented, Nov 5, 2016

Hi ! When this fix will be deployed ?

0reactions
devel-pacommented, Jan 23, 2017

Tested, same behavior, making onCompile runs twice.

Happens on build or on first watch.

Update:

preCompile: function () {
      return copyFile('./app/assets/test.json', './test/test.json');
    },

runs twice

preCompile: function () {
      return [copyFile('./app/assets/test.json', './test/test.json')];
    },

runs thrice

Anyway, on first compile makes onCompile stuff to fail as I’m running tests with that

Read more comments on GitHub >

github_iconTop Results From Across the Web

Brunch: Commands
Brunch builds, lints, compiles, concatenates and shrinks your HTML5 app in an ultra-simple way. No more Grunt / Gulp mess.
Read more >
c# - alternate options for infinite loop
We are running one third party application which uses C#, SQL SERVER. We have created one other application which prints the pass. Basically...
Read more >
Best Sports Bar Brunch near me in Chicago, IL
Reviews on Sports Bar Brunch in Chicago, IL - Radio Room, Broken Barrel ... Great spot to watch sports - We watched Fifa...
Read more >
Joomla. Infinite loop detected in JError
occurs due to some parameters in configuration.php that are wrongly filled in. This may happen when you have moved a Joomla 1.7 site...
Read more >
two cursors in one sp getting infinite loop
I can see, sanjeeva, that you've edited your post after our two replies, but I'm not really sure what you've added. You're always...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found