Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Missing module after running brunch watch -s #1271

Closed
Itagiba opened this issue Apr 1, 2016 · 13 comments
Closed

Missing module after running brunch watch -s #1271

Itagiba opened this issue Apr 1, 2016 · 13 comments
Labels

Comments

@Itagiba
Copy link

Itagiba commented Apr 1, 2016

Description

Hello, I am having real issues with brunch at the moment. The error is not very consistent because it has not happened in 10hrs but it seems that sometimes when I run brunch watch -s I lose some of the configuration of the files and it throws these warnings followed by the following error below:

01 Apr 09:21:22 - warn: config.files.javascripts.defaultPaths was removed
01 Apr 09:21:22 - warn: config.files.stylesheets.defaultPaths was removed
01 Apr 09:21:22 - warn: config.files.templates.defaultPaths was removed
01 Apr 09:21:22 - error: Initialization error - You probably need to execute `npm install` to install brunch plugins. Error: Cannot find module './lib/core.js'

I have no idea why it suddenly loses the paths and ./lib/core.js module. I follow the instructions it gives me and reinstall brunch with npm install, do a brunch watch -s again, it is also worth pointing that it labels brunch as extraneous (whatever that means)

package-name@0.0.1 /Users/lcouto/.Trash/dk-find-out 15.24.21
├── brunch@2.5.3  extraneous
└── node-sass@3.4.2  extraneous

This still does not work. I then proceed in installing brunch globally npm install brunch -g. But I get the same error and instruction to do an npm install again. I keep going around in circles with this. What on earth is happening?

Environment

  1. Brunch: 2.5.3
  2. Node:v4.4.1
  3. NPM:3.8.3
  4. Operating system: MAC OX Yosemite 10.10.5

package.json contents

  "author": "Your Name",
  "name": "package-name",
  "description": "Package description",
  "version": "0.0.1",
  "homepage": "",
  "repository": {
    "type": "git",
    "url": ""
  },
  "engines": {
    "node": "~0.6.10"
  },
  "scripts": {
    "start": "brunch watch -s",
    "test": "brunch test"
  },
  "dependencies": {
    "autoprefixer": "^6.3.5",
    "clean-css-brunch": ">= 1.0 < 1.4",
    "css-brunch": ">= 1.0 < 1.4",
    "handlebars-brunch": ">= 1.0 < 1.4",
    "javascript-brunch": ">= 1.0 < 1.6",
    "postcss-brunch": "^0.5.0",
    "sass-brunch": "^1.9.2",
    "uglify-js-brunch": ">= 1.0 < 1.4"
  },
  "devDependencies": {
    "chai": "1.2.0",
    "sinon": "1.4.2",
    "sinon-chai": "2.1.2"
  }
}

brunch config contents

exports.config =
  # Edit the next line to change default build path.
  paths:
    public: 'public'

  plugins:
    postcss:
      processors: [
        require('autoprefixer')(['last 8 versions'])
      ]

  files:
    javascripts:
      # Defines what file will be generated with `brunch generate`.
      defaultExtension: 'js'
      # Describes how files will be compiled & joined together.
      # Available formats:
      # * 'outputFilePath'
      # * map of ('outputFilePath': /regExp that matches input path/)
      # * map of ('outputFilePath': function that takes input path)
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/
        'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
        'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
      # Defines compilation order.
      # `vendor` files will be compiled before other ones
      # even if they are not present here.
      order:
        before: [
          'vendor/scripts/console-helper.js',
          'vendor/scripts/modernizr.custom.50279.js',
          'vendor/scripts/jquery-1.8.2.min.js',
          'vendor/scripts/jquery-ui.js',
          'vendor/scripts/respond.min.js',
          'vendor/scripts/underscore-1.4.4.js',
          'vendor/scripts/backbone-1.0.0.js',
          'vendor/scripts/backbone-mediator.js',
          'vendor/scripts/tappable-9.9.9.js',
          'vendor/scripts/jquery.hammer.js',
          'vendor/scripts/masonry.pkgd.js',
          'vendor/scripts/jquery.mCustomScrollbar.js',
          'vendor/scripts/jquery.ui.touch-punch.js'

          # Twitter Bootstrap jquery plugins
          #'vendor/scripts/bootstrap/bootstrap-transition.js',
          #'vendor/scripts/bootstrap/bootstrap-alert.js',
          #'vendor/scripts/bootstrap/bootstrap-button.js',
          #'vendor/scripts/bootstrap/bootstrap-carousel.js',
          #'vendor/scripts/bootstrap/bootstrap-collapse.js',
          #'vendor/scripts/bootstrap/bootstrap-dropdown.js',
          #'vendor/scripts/bootstrap/bootstrap-modal.js',
          #'vendor/scripts/bootstrap/bootstrap-tooltip.js',
          #'vendor/scripts/bootstrap/bootstrap-popover.js',
          #'vendor/scripts/bootstrap/bootstrap-scrollspy.js',
          #'vendor/scripts/bootstrap/bootstrap-tab.js',
          #'vendor/scripts/bootstrap/bootstrap-typeahed.js'
        ]
        after: [
          'test/vendor/scripts/test-helper.js'
        ]

    stylesheets:
      defaultExtension: 'less'
      joinTo:
        'stylesheets/app.css': /^(app|vendor)/
        'test/stylesheets/test.css': /^test/
      # moved all scss files to before
      # using after was temperamental
      order:
       before: [
         'app/styles/mixins.scss',
         'app/styles/main.scss',
         'app/styles/header.scss',
         'app/styles/footer.scss',
         'app/styles/articles.scss',
         'app/styles/landing.scss',
         'app/styles/search.scss',
         'app/styles/gallery.scss',
         'app/styles/video.scss',
         'app/styles/quiz.scss',
         'app/styles/explore.scss',
         'app/styles/hover.scss',
         'app/styles/ie.scss'
       ]
       after: [
       ]
  # Updated to sass-brunch@1.9
  # Added new path for sass files.
      defaultExtension: 'scss'
      joinTo:
        'stylesheets/app.css': /^app\/styles/
        'stylesheets/global.css': /^app\/sass\/config/

    templates:
      defaultExtension: 'hbs'
      joinTo: 'javascripts/app.js'

  # Change this if you're using something other than backbone (e.g. 'ember').
  # Content of files, generated with `brunch generate` depends on the setting.
  # framework: 'backbone'

  # Settings of web server that will run with `brunch watch [--server]`.
  # server:
  #   # Path to your server node.js module.
  #   # If it's commented-out, brunch will use built-in express.js server.
  #   path: 'server.coffee'
  #   port: 3333
  #   # Run even without `--server` option?
  #   run: yes

Unfortunately I am unable to create a demo app but I hope that the information above gives you enough info.

@goshacmd
Copy link
Contributor

goshacmd commented Apr 2, 2016

01 Apr 09:21:22 - warn: config.files.javascripts.defaultPaths was removed
01 Apr 09:21:22 - warn: config.files.stylesheets.defaultPaths was removed
01 Apr 09:21:22 - warn: config.files.templates.defaultPaths was removed

It doesn't mean it was "removed" from your config. It simply warns you that Brunch no longer uses this property so that you won't rely on it (its support was dropped back in 1.1; the warning was added in 2.3 because many people still had it in their configs)

Not a big deal.


01 Apr 09:21:22 - error: Initialization error - You probably need to execute npm install to install brunch plugins. Error: Cannot find module './lib/core.js'

It is reporting an error that occurs when brunch is trying to require one of the plugins listed in package.json. I copied your package.json and npm installed it locally, then tried running brunch and it was able to require all the plugins specified. (Which means all plugins you are using are proper)

The issue could be on your side. Perhaps you (or something else) have accidentally deleted that file from node_modules/something. Can you try removing the entire node_modules and doing a fresh npm install to see if it fixes your issue?

@Itagiba
Copy link
Author

Itagiba commented Apr 2, 2016

Thanks for your reply. I have deleted the package locally and checked-out another copy but now I am getting another error after running npm start (which I ran after npm install)

> package-name@0.0.1 start /Users/juanbess/github/passthru-web
> brunch watch -s

/usr/local/lib/node_modules/brunch/lib/helpers.js:460
      throw new Error("couldn\'t load config " + configPath + ". " + error);
      ^

Error: couldn't load config config. SyntaxError: In /Users/juanbess/github/passthru-web/config.coffee, multiple object literal properties named "defaultExtension"
    at Object.exports.loadConfig (/usr/local/lib/node_modules/brunch/lib/helpers.js:460:13)
    at /usr/local/lib/node_modules/brunch/lib/commands/watch.js:156:24
    at /usr/local/lib/node_modules/brunch/lib/helpers.js:494:14
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v4.4.1
npm ERR! npm  v3.7.3
npm ERR! code ELIFECYCLE
npm ERR! package-name@0.0.1 start: `brunch watch -s`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the package-name@0.0.1 start script 'brunch watch -s'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the package-name package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     brunch watch -s
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs package-name
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls package-name
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/juanbess/github/passthru-web/npm-debug.log

It seems to fail here:

"scripts": { "start": "brunch watch -s", "test": "brunch test" },

But does not give me any meanful information. Except the brunch watch -s command itself. Do I need to reinstall brunch? My current version is
1.4.4

@goshacmd
Copy link
Contributor

goshacmd commented Apr 2, 2016

Just look at the error message itself

Error: couldn't load config config. SyntaxError: In /Users/juanbess/github/passthru-web/config.coffee, multiple object literal properties named "defaultExtension"

It's pretty descriptive. It's not a brunch issue, it's a CoffeeScript syntax error (you probably have a few defaultExtension keys in the same object)

Either way, since defaultExtension is no longer supported, you can just delete it.

@Itagiba
Copy link
Author

Itagiba commented Apr 2, 2016

It does not make sense to me. I need to track the files of a particular extension in order to join them into another file. If I remove the defaultExtension, I get another error with jointo:


      throw new Error("couldn\'t load config " + configPath + ". " + error);
      ^

Error: couldn't load config config. SyntaxError: In /Users/juanbess/github/passthru-web/config.coffee, multiple object literal properties named "joinTo"

@goshacmd
Copy link
Contributor

goshacmd commented Apr 2, 2016

Because you also have several joinTos in the same object.

{ a: 1, a: 2 } — this doesn't make sense. That's not valid CoffeeScript/JS. You simply can't have several values assigned to the same key this way.

Why do you need to care about extensions so much?

Wouldn't this be an acceptable join config?

  stylesheets:
    joinTo:
        'stylesheets/app.css': [/^(app|vendor)(.+)\.(?!scss)/, /^app\/styles\/(.+)\.scss/]
        'test/stylesheets/test.css': /^test/
        'stylesheets/global.css': /^app\/sass\/config/
      # moved all scss files to before
      # using after was temperamental
      order:
       before: [
         'app/styles/mixins.scss',
         'app/styles/main.scss',
         'app/styles/header.scss',
         'app/styles/footer.scss',
         'app/styles/articles.scss',
         'app/styles/landing.scss',
         'app/styles/search.scss',
         'app/styles/gallery.scss',
         'app/styles/video.scss',
         'app/styles/quiz.scss',
         'app/styles/explore.scss',
         'app/styles/hover.scss',
         'app/styles/ie.scss'
       ]
       after: [
       ]

where [/^(app|vendor)(.+)\.(?!scss)/, /^app\/styles\/(.+)\.scss/] should achieve more or less what you want:

non-scss files from app and vendor plus scss files only from app/styles

(note that the regexp might need some tweaking but you get the idea)

If your scss and less styles all live under app/styles, it can be a simpler /^(app\/styles)|vendor/

@Itagiba
Copy link
Author

Itagiba commented Apr 2, 2016

If it helps, here is my config file:

exports.config =
  # Edit the next line to change default build path.
  paths:
    public: 'public'

  plugins:
    postcss:
      processors: [
        require('autoprefixer')(['last 8 versions'])
      ]

  files:
    javascripts:
      # Defines what file will be generated with `brunch generate`.
      defaultExtension: 'js'
      # Describes how files will be compiled & joined together.
      # Available formats:
      # * 'outputFilePath'
      # * map of ('outputFilePath': /regExp that matches input path/)
      # * map of ('outputFilePath': function that takes input path)
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/
        'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
        'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
      # Defines compilation order.
      # `vendor` files will be compiled before other ones
      # even if they are not present here.
      order:
        before: [
          'vendor/scripts/console-helper.js',
          'vendor/scripts/modernizr.custom.50279.js',
          'vendor/scripts/jquery-1.8.2.min.js',
          'vendor/scripts/jquery-ui.js',
          'vendor/scripts/respond.min.js',
          'vendor/scripts/underscore-1.4.4.js',
          'vendor/scripts/backbone-1.0.0.js',
          'vendor/scripts/backbone-mediator.js',
          'vendor/scripts/tappable-9.9.9.js',
          'vendor/scripts/jquery.hammer.js',
          'vendor/scripts/masonry.pkgd.js',
          'vendor/scripts/jquery.mCustomScrollbar.js',
          'vendor/scripts/jquery.ui.touch-punch.js'

          # Twitter Bootstrap jquery plugins
          #'vendor/scripts/bootstrap/bootstrap-transition.js',
          #'vendor/scripts/bootstrap/bootstrap-alert.js',
          #'vendor/scripts/bootstrap/bootstrap-button.js',
          #'vendor/scripts/bootstrap/bootstrap-carousel.js',
          #'vendor/scripts/bootstrap/bootstrap-collapse.js',
          #'vendor/scripts/bootstrap/bootstrap-dropdown.js',
          #'vendor/scripts/bootstrap/bootstrap-modal.js',
          #'vendor/scripts/bootstrap/bootstrap-tooltip.js',
          #'vendor/scripts/bootstrap/bootstrap-popover.js',
          #'vendor/scripts/bootstrap/bootstrap-scrollspy.js',
          #'vendor/scripts/bootstrap/bootstrap-tab.js',
          #'vendor/scripts/bootstrap/bootstrap-typeahed.js'
        ]
        after: [
          'test/vendor/scripts/test-helper.js'
        ]

    stylesheets:
      defaultExtension: 'scss'
      joinTo:
        'stylesheets/app.css': /^(app|vendor)/
        'test/stylesheets/test.css': /^test/
      # moved all scss files to before
      # using after was temperamental
      order:
       before: [
         'app/styles/mixins.scss',
         'app/styles/main.scss',
         'app/styles/header.scss',
         'app/styles/footer.scss',
         'app/styles/articles.scss',
         'app/styles/landing.scss',
         'app/styles/search.scss',
         'app/styles/gallery.scss',
         'app/styles/video.scss',
         'app/styles/quiz.scss',
         'app/styles/explore.scss',
         'app/styles/hover.scss',
         'app/styles/ie.scss'
       ]
       after: [
       ]
  # Updated to sass-brunch@1.9
  # Added new path for sass files.
      defaultExtension: 'scss'
      joinTo:
        'stylesheets/app.css': /^app\/styles/
        'stylesheets/global.css': /^app\/sass\/config/

    templates:
      defaultExtension: 'hbs'
      joinTo: 'javascripts/app.js'

  # Change this if you're using something other than backbone (e.g. 'ember').
  # Content of files, generated with `brunch generate` depends on the setting.
  # framework: 'backbone'

  # Settings of web server that will run with `brunch watch [--server]`.
  # server:
  #   # Path to your server node.js module.
  #   # If it's commented-out, brunch will use built-in express.js server.
  #   path: 'server.coffee'
  #   port: 3333
  #   # Run even without `--server` option?
  #   run: yes

@Itagiba
Copy link
Author

Itagiba commented Apr 2, 2016

Ok, the good news is that it is now compiling but the actual project returns a blank page and gives me the following error in the console:

`vendor.js:61 Uncaught Error: Cannot find module "views/templates/private_mode"require @ vendor.js:61(anonymous function) @ vendor.js:40window.require.define.application @ app.js:99initModule @ vendor.js:46require @ vendor.js:55(anonymous function) @ vendor.js:40window.require.define.initialize @ app.js:277initModule @ vendor.js:46require @ vendor.js:55(anonymous function) @ 1:55`

I believe the above not to be related to brunch unless it is how it exports the vendor.js file. the views/templates/private_mode does exist so I will have to look into this.

Thanks for your help.

@goshacmd
Copy link
Contributor

goshacmd commented Apr 4, 2016

If you can't fix that issue and believe it is being caused by brunch, you can always share a small app that reproduces it so that we can take a look

@Itagiba
Copy link
Author

Itagiba commented Apr 5, 2016

Thank you, I have been doing some research in the little time I have and it seems that it is indeed a brunch issue. It does not seem to be finding my templates and I wonder if it is caused by where I am compiling these in my brunch.coffee file:

exports.config =
  # Edit the next line to change default build path.
  paths:
    public: 'public'

  plugins:
    postcss:
      processors: [
        require('autoprefixer')(['last 8 versions'])
      ]

  files:
    javascripts:
      # Defines what file will be generated with `brunch generate`.
      defaultExtension: 'js'
      # Describes how files will be compiled & joined together.
      # Available formats:
      # * 'outputFilePath'
      # * map of ('outputFilePath': /regExp that matches input path/)
      # * map of ('outputFilePath': function that takes input path)
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/
        'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
        'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
      # Defines compilation order.
      # `vendor` files will be compiled before other ones
      # even if they are not present here.
      order:
        before: [
          'vendor/scripts/console-helper.js',
          'vendor/scripts/modernizr.custom.50279.js',
          'vendor/scripts/jquery-1.8.2.min.js',
          'vendor/scripts/jquery-ui.js',
          'vendor/scripts/respond.min.js',
          'vendor/scripts/underscore-1.4.4.js',
          'vendor/scripts/backbone-1.0.0.js',
          'vendor/scripts/backbone-mediator.js',
          'vendor/scripts/tappable-9.9.9.js',
          'vendor/scripts/jquery.hammer.js',
          'vendor/scripts/masonry.pkgd.js',
          'vendor/scripts/jquery.mCustomScrollbar.js',
          'vendor/scripts/jquery.ui.touch-punch.js'

          # Twitter Bootstrap jquery plugins
          #'vendor/scripts/bootstrap/bootstrap-transition.js',
          #'vendor/scripts/bootstrap/bootstrap-alert.js',
          #'vendor/scripts/bootstrap/bootstrap-button.js',
          #'vendor/scripts/bootstrap/bootstrap-carousel.js',
          #'vendor/scripts/bootstrap/bootstrap-collapse.js',
          #'vendor/scripts/bootstrap/bootstrap-dropdown.js',
          #'vendor/scripts/bootstrap/bootstrap-modal.js',
          #'vendor/scripts/bootstrap/bootstrap-tooltip.js',
          #'vendor/scripts/bootstrap/bootstrap-popover.js',
          #'vendor/scripts/bootstrap/bootstrap-scrollspy.js',
          #'vendor/scripts/bootstrap/bootstrap-tab.js',
          #'vendor/scripts/bootstrap/bootstrap-typeahed.js'
        ]
        after: [
          'test/vendor/scripts/test-helper.js'
        ]

  stylesheets:
    joinTo:
        'stylesheets/app.css': [/^(app|vendor)(.+)\.(?!scss)/, /^app\/styles\/(.+)\.scss/]
        'test/stylesheets/test.css': /^test/
        'stylesheets/global.css': /^app\/sass\/config/
      # moved all scss files to before
      # using after was temperamental
      order:
       before: [
         'app/styles/mixins.scss',
         'app/styles/main.scss',
         'app/styles/header.scss',
         'app/styles/footer.scss',
         'app/styles/articles.scss',
         'app/styles/landing.scss',
         'app/styles/search.scss',
         'app/styles/gallery.scss',
         'app/styles/video.scss',
         'app/styles/quiz.scss',
         'app/styles/explore.scss',
         'app/styles/hover.scss',
         'app/styles/ie.scss'
       ]

   **  templates:
       defaultExtension: 'hbs'
       joinTo: 'javascripts/app.js'
**
       after: [
       ]



  # Change this if you're using something other than backbone (e.g. 'ember').
  # Content of files, generated with `brunch generate` depends on the setting.
  # framework: 'backbone'

  # Settings of web server that will run with `brunch watch [--server]`.
  # server:
  #   # Path to your server node.js module.
  #   # If it's commented-out, brunch will use built-in express.js server.
  #   path: 'server.coffee'
  #   port: 3333
  #   # Run even without `--server` option?
  #   run: yes

I have only used Gulp.js before and brunch seems to be a bit opinionated. I have upgraded to version brunch - 2.6.1 (globally) but it is still not solving the problem. I am also getting an error (only shown in terminal, not console) but it is a

error: [TypeError: Cannot read property 'indexOf' of undefined]

Type error which is not very clear.

@goshacmd
Copy link
Contributor

goshacmd commented Apr 5, 2016

The config seems ok, nothing stands out that could be causing it... that said, the issue can be somewhere in your code or the plugins (or the versions of the plugins)

Please provide a small app that demonstrates the issue to make it easier for me to help you.

@Florian-R
Copy link
Contributor

@goshakkk Can reproduce with the dead-simple-skeleton. Seems related to Linux and fs.write, see microsoft/vscode#4727

@paulmillr paulmillr added the bug label May 16, 2016
@robbiewxyz
Copy link

Okay, I've got what I think is the same problem: when my editor (NeoVim) is set to do non-atomic saves, simply writing onto the file, I get lots of messy problems with dependencies/etc. like @Itagiba described. The problem appears to go away when I switch to atomic writes (write elsewhere and copy) or by setting usePolling: true.

It seems like maybe this issue should go upstream to paulmillr/chokidar.

@robbiewxyz
Copy link

I guess that us getting these issues more than Gulp/Webpack/etc means Brunch is fast enough the OS can't keep up. So yay Brunch! 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants