GithubHelp home page GithubHelp logo

browserify-rails / browserify-rails Goto Github PK

View Code? Open in Web Editor NEW
704.0 704.0 92.0 461 KB

Browserify + Rails = a great way to modularize your legacy JavaScript

License: MIT License

Ruby 93.43% JavaScript 0.17% CSS 0.80% HTML 5.60%
browserify commonjs rails rails-browserify ruby

browserify-rails's Introduction

browserify-rails

This project is currently in maintenance mode. New contributors are more than welcome!

Gem Version

This library adds CommonJS module support to Sprockets (via Browserify).

It lets you mix and match //= require directives and require() calls for including plain javascript files as well as modules. However, it is important to remember that once you are into code that is being browserified you can no longer use sprockets-style require (so no //= require). In many cases, it makes sense to put all your sprockets-required code in a separate file or at the very least at the top of your main JavaScript file. Then use require() to pull in the CommonJS code.

  1. Manage JS modules with npm
  2. Serve assets with Sprockets
  3. Require modules with require() (without separate //= require directives)
  4. Only build required modules
  5. Require npm modules in your Rails assets
  6. Require modules relative to asset paths (ie app/assets/javascript) with non-relative syntax (see below before using)
  7. Configure browserify options for each JavaScript file so you can mark modules with --require, --external, etc

Should you use this gem?

As the primary developer, I'm going to offer some opiniated advice. The sweet spot for this gem is for Rails projects with legacy JavaScript (not using CommonJS/modules). This gem is a great way to make it possible to rewrite that legacy JavaScript to CommonJS on a timeline that you dictate. Then consider stepping off the Rails asset pipeline or using another gem.

If you're starting a new Rails project today, I highly recommend looking at alternatives to this gem. The primary reason is that this gem, while it works well, is not as efficient as most would like for local development. Also a lot has changed over the last couple of years.

An example of that change is this project from Rails:

rails/webpacker

This is a huge step in the right direction for the Rails community. In the past, it has been extremely frustrating working with JavaScript on the asset pipeline. The good news is you have a lot of great choices. If I were starting a new Rails project today, I think the safest choice is one in which you have a Procfile that kicks off a separate Webpack build and you use zero Rails magic. A slightly less safe but maybe more convenient choice would be trying rails/webpacker or another gem. The choice is yours.

For more discussion on this topic, see issues 203, 161, 43, etc.

Getting Started

Add this line to your application's Gemfile:

gem "browserify-rails"

Create package.json in your Rails root:

{
  "name": "something",
  "dependencies" : {
    "browserify": "^14.0.0",
    "browserify-incremental": "^3.1.0"
  },
  "license": "MIT",
  "engines": {
    "node": ">= 0.10"
  }
}

Then run:

npm install

Then start writing CommonJS, and everything will magically work!:

// foo.js
module.exports = function (n) { return n * 11 }

// application.js
var foo = require('./foo');
console.log(foo(12));

Gotchas with require and module.exports

Do not put module.exports or require() in JavaScript comments or strings. Doing so will certainly cause issues with compilation that are difficult to track down.

This happens because browserify-rails works by parsing your JavaScript files for these keywords that indicate whether it is a module, or is requiring a module. If a file meets one of these criteria, browserify will compile the modules as expected.

Because browserify-rails is working within the restraints of Ruby/Sprockets, the parsing is done by Ruby and therefore does not know whether it is a JavaScript string, comment, or function.

CoffeeScript

For CoffeeScript support, make sure to follow the standard rails .js.coffee naming convention. You'll also need to add the npm package coffeeify as a dependency:

{
  // ...
  "dependencies" : {
    // ...
    "coffeeify": "~0.6"
  }
}

and configure browserify_rails accordingly:

config.browserify_rails.commandline_options = "-t coffeeify --extension=\".js.coffee\""

Requirements

  • node-browserify 4.x
  • browserify-incremental

Configuration

Global configuration

You can configure different options of browserify-rails by adding one of the lines mentioned below into your config/application.rb or your environment file (config/environments/*.rb):

class My::Application < Rails::Application
  # Specify the file paths that should be browserified. We browserify everything that
  # matches (===) one of the paths. So you will most likely put lambdas
  # regexes in here.
  #
  # By default only files in /app and /node_modules are browserified,
  # vendor stuff is normally not made for browserification and may stop
  # working.
  config.browserify_rails.paths << /vendor\/assets\/javascripts\/module\.js/

  # Environments in which to generate source maps
  #
  # The default is none
  config.browserify_rails.source_map_environments << "development"

  # Should the node_modules directory be evaluated for changes on page load
  #
  # The default is `false`
  config.browserify_rails.evaluate_node_modules = true

  # Force browserify on every found JavaScript asset if true.
  # Can be a proc.
  #
  # The default is `false`
  config.browserify_rails.force = ->(file) { File.extname(file) == ".ts" }

  # Command line options used when running browserify
  #
  # can be provided as an array:
  config.browserify_rails.commandline_options = ["-t browserify-shim", "--fast"]

  # or as a string:
  config.browserify_rails.commandline_options = "-t browserify-shim --fast"

  # Define NODE_ENV to be used with envify
  #
  # defaults to Rails.env
  config.browserify_rails.node_env = "production"

browserify-incremental

browserify-incremental is used to cache browserification of CommonJS modules. One of the side effects is that the absolute module path is included in the emitted JavaScript. Most people do not want this for production code so browerify-incremental is current disabled for the production and staging environments. Note that counter-intuitively, browserify-incremental helps even with a single build pass of your code because typically the same modules are used multiple times. So it helps even for say asset compilation on a push to Heroku.

Enabling browserify-incremental in production

To enable browserify-incremental in production, add the following line to config/environments/production.rb:

config.browserify_rails.use_browserifyinc = true

Multiple bundles

node-browserify supports multiple bundles and so do does rails-browserify. It does this using config/browserify.yml. Below is an example.

Say you have three JavaScript files and one is a huge library you would like to use in both. Browserify lets you mark that huge library with --require in one file (to both bundle it and mark it with a special internal ID) and then require it in the other file and mark it with --external (so it is not bundled into the file but instead accessed via browserify internals using that special ID). Note that this only works when the file that has the library bundled is loaded before the file that uses the library with --external.

javascript:
  main:
    require:
      - a_huge_library
  secondary:
    external:
      - a_huge_library

Note that any valid browserify option is allowed in the YAML file but not all use cases have been considered. If your use case does not work, please open an issue with a runnable example of the problem including your browserify.yml file.

Inside Isolated Engines

To make browserify-rails work inside an isolated engine, add the engine app directory to the browserify-rails paths (inside engine.rb):

config.browserify_rails.paths << -> (p) { p.start_with?(Engine.root.join("app").to_s) }

If you wish to put the node_modules directory within the engine, you have some control over it with:

config.browserify_rails.node_bin = "some/directory"

Example setup

Refer to this repo for setting up this gem with ES6 and all front-end goodies like react and all - github.com/gauravtiwari/browserify-rails

Support for rails asset directories as non-relative module sources

In the Rails asset pipeline, it is common to have files in app/assets/javascripts and being able to do //= require some_file which exists in one of the asset/javascript directories. In some cases, it is useful to have similar functionality with browserify. This has been added by putting the Rails asset paths into NODE_PATH environment variable when running browserify.

But this comes at a large cost: right now, it appears to break source maps. This might be a bug or a fixable breakage but it hasn't been solved yet. The use of NODE_PATH is also contentious in the NodeJS community.

Why leave it in? Because some typical Rails components break without it. For example, jasmine-rails expects to be able to move JavaScript to different depths. So if you do a relative require from spec/javascript to app/assets/javascripts, your tests will fail to run when RAILS_ENV=test.

So if you really need this, use it. But if you really need it for files that are not tests, you should definitely figure out an alternative. Support for this may go away if we cannot fix the issue(s) with source maps being invalid.

Deploying to Heroku

Heroku is a very common target for deploying. You'll have to add custom buildpacks that run bundle and npm install on the target machine.

$ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-nodejs.git
$ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-ruby.git

Using Browserify Transforms

You can easily use a browserify transform by making some additions to your package.json and creating a .babelrc. For example, here is how you can add ES6 support in your app:

  1. Add babelify and babel-preset-es2015 to your package.json in your app's root directory either by editing the file directly and running npm install or using npm install babelify --save and npm install babel-preset-es2015 --save
  2. Update your package.json to contain the babelify transform by adding the following lines
   "browserify": {
    "transform": [
      [
        "babelify"
      ]
    ]
  }
  1. Create a .babelrc file in the project root with the following contents
{
  "plugins": [],
  "presets": ["es2015"]
}
  1. Create some .es6 files and require them with var m = require('./m.es6') or import m from './m.es6'
  2. Restart your server, and you now have ES6 support!

Troubleshooting

Clear the asset pipeline cache

The Rails asset pipeline caches some files in the tmp directory inside Rails root. It can happen that sometimes the cache does not get invalidated correctly. You can manually clear the cache in at least two ways:

  1. rake tmp:cache:clear
  2. rm -rf ./tmp (when in the root directory of the Rails project)

The second method is definitely brute force but if you experience issues, it is definitely worth trying before spending too much time debugging why something that is browserified appears to not match the sources files.

Javascript Tests

If you want to use browserify to process test files as well, you will need to configure browserify-rails to process files in your spec or test directories.

config.browserify_rails.paths << -> (p) { p.start_with?(Rails.root.join("spec/javascripts").to_s) }

Acceptance Test Failures

If you have Sprockets precompile multiple JS files, each of which include certain browserified files, your acceptance tests may timeout before some of the assets have finished compiling.

To avoid this problem, run rake assets:precompile before running your acceptance tests.

Contributing

Pull requests appreciated. Pull requests will not be rejected based on ideological neurosis of either the NodeJS or the Ruby on Rails communities. In other words, technical needs are respected.

Running the dummy Rails app

There is a dummy rails app in test/dummy. You can change to that directory and run bundle install and then bundle exec rails server. You can see the test JavaScript files in app/assets/javascripts so try loading one -- for example http://localhost:3000/assets/application.js.

You can use this dummy app to try out your coding/refactoring/hacking ideas and also see how the tests are written. To run the tests, run bundle exec rake test in the root directory of the browserify-rails code (not in the dummy app).

Potential areas of change (contributions welcome)

Multiple modules

Often one has one main module (say a library module) and other modules that consume the main module. It would be nice to be able to establish this relationship in the YAML file to avoid having to manually manage the require and external entries for the involved modules.

Alternatives

Use webpack or browserify directly instead of the asset pipeline

Use a tool like ProcMan to kick off a webpack or browserify process to rebuild your JavaScript on change. Reference the bundle in your Rails template and away you go. With webpack, you can even use the dev server and point to the dev server port in your Rails template to load JavaScript directly from webpack (it'll block on build so you'll always get your latest code). This does require configuring webpack hot middleware to have a port (see __webpack_hmr goes to the wrong port and fails).

Contributors

browserify-rails's People

Contributors

cymen avatar darep avatar dependabot[bot] avatar derekkraan avatar dkamenka avatar ericboehs avatar gabrielecirulli avatar gauravtiwari avatar guiceolin avatar hajpoj avatar itsthatguy avatar jaredbeck avatar jasonroelofs avatar jayrbolton avatar joshfrench avatar justin808 avatar lautis avatar lukaszsagol avatar martenlienen avatar marvwhere avatar matthewlehner avatar morenoh149 avatar onyxrev avatar posgarou avatar rymohr avatar sunflat avatar widdershin avatar xrnm avatar yachibit avatar yui-knk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

browserify-rails's Issues

Does not work with sass-rails and sprockets

When i do bundle install

Bundler could not find compatible versions for gem "sprockets":
  In Gemfile:
    browserify-rails (~> 0.9) ruby depends on
      sprockets (~> 2.2) ruby

    sass-rails (~> 5.0) ruby depends on
      sprockets (3.0.0)

and after downgrading sass-rails to 4.0, it also have problem:

Bundler could not find compatible versions for gem "sprockets":
  In Gemfile:
    browserify-rails (~> 0.9) ruby depends on
      sprockets (~> 2.2) ruby

    web-console (~> 2.0) ruby depends on
      sprockets-rails (< 4.0, >= 2.0) ruby depends on
        sprockets (3.0.0)

Performance

So we have performance issues sometimes. I want things to work faster locally and I am seeing some potential areas to make things faster:

  • when source maps are enabled, everything gets source maps including node_modules -- I could live without source maps for node_modules by default with option to turn them on
  • browserify supports a noparse option -- configuring it manually is annoying but automating it seems risky too -- potentially, we could do a noparse if we had a cache that told us if a file was CommonJS or not (if it needed to be browserified)
  • browserify has a --fast option -- it would be good to know if

For caching, we need something in memory (or in filesystem, I'd prefer memory). That cache would need the last modified time for a file along with other things. This would only be present for development -- in production with Rails, the assets are precompiled so browserify-rails should never need to be running in production (which frees us up on how we implement this quite a bit, let me know if my assumptions are wrong here).

This isn't comprehensive but I want to get the conversation going and see if anyone else is thinking about this (I know @gabrielecirulli is -- thanks to him, browserify-incremental is in with #35).

Cannot handle symbolic links

Error while running `/vagrant/eagle/./node_modules/.bin/browserify -d --list -`:


events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Cannot find module 'lmn-monkey' from '/vagrant/eagle/app/assets/javascripts/spree/frontend'
lrwxr-xr-x  1 callumacrae  staff     42 10 Nov 12:30 lmn-monkey -> /Users/callumacrae/Sites/lostmyname/monkey

This is pretty important when using npm link.

browserify-incremental failure

The browserify build succeeds initially (after deleting the tmp dir and restarting Rails), but fails when a file is changed and the page is reloaded.

The re-builds succeed when I disable browserify-incremental like this:

config.browserify_rails.use_browserifyinc = false
Notes:
  • I'm using browserify-rails within a Rails engine. I'm not sure if the problem is related to this.
  • I haven't been able to get the engine to register the browserify.yml file, so I'm passing the --require options as commandline_options (as seen in the config below).
  • I'm using browserify version 6.3.4 and browserify-incremental version 1.4.0. I've tried the latest versions of each as well as earlier versions of each and the issue is the same.
  • If I revert the change to the .jsx file and reload the page, the build is once again successful.
package.json
{
  "name": "dbx-ui",
  "devDependencies": {
    "browserify": "~> 6.3.4",
    "browserify-incremental": "1.4.0",
    "reactify": "^1.1.0"
  },
  "license": "MIT",
  "engines": {
    "node": ">= 0.12"
  },
  "dependencies": {
    "d3": "^3.5.5",
    "jquery": "1.11.2",
    "metrics-graphics": "^2.3.0",
    "react": "^0.13.1",
    "react-bootstrap": "^0.20.2"
  }
}
engine config:
    # add engine assets to browserify path
    config.browserify_rails.paths << lambda { |p| p.start_with?(Engine.root.join("app", "assets", "commonjs").to_s)  }

    # contain node modules within engine
    config.browserify_rails.node_bin = Engine.root.join('node_modules', '.bin')

    # transform jsx
    config.browserify_rails.commandline_options = [
      "-t reactify --extension=\".js.jsx\"",
      '-r react',
      '-r jquery',
      '-r dbx_ui_engine/dbx_ui_commonjs',
      '-v'
    ]
successful initial build:
Browserify: /Users/lynn/Code/Healthbox/databoxapi/clients/ui/lib/dbx_ui_engine/node_modules/.bin/browserifyinc -t reactify --extension=".js.jsx
" -r react -r jquery -r dbx_ui_engine/dbx_ui_commonjs -v --list --cachefile="/Users/lynn/Code/Healthbox/databoxapi/tmp/cache/browserify-rails/b
rowserifyinc-cache.json" -o "/Users/lynn/Code/Healthbox/databoxapi/tmp/cache/browserify-rails/output20150408-18766-134fbsb" -
Browserify: /Users/lynn/Code/Healthbox/databoxapi/clients/ui/lib/dbx_ui_engine/node_modules/.bin/browserifyinc -t reactify --extension=".js.jsx
" -r react -r jquery -r dbx_ui_engine/dbx_ui_commonjs -v --cachefile="/Users/lynn/Code/Healthbox/databoxapi/tmp/cache/browserify-rails/browseri
fyinc-cache.json" -o "/Users/lynn/Code/Healthbox/databoxapi/tmp/cache/browserify-rails/output20150408-18766-1056246" -
error (after .jsx file is changed):
Browserify: /Users/lynn/Code/Healthbox/databoxapi/clients/ui/lib/dbx_ui_engine/node_modules/.bin/browserifyinc -t reactify --extension=".js.jsx
" -r react -r jquery -r dbx_ui_engine/dbx_ui_commonjs -v --list --cachefile="/Users/lynn/Code/Healthbox/databoxapi/tmp/cache/browserify-rails/b
rowserifyinc-cache.json" -o "/Users/lynn/Code/Healthbox/databoxapi/tmp/cache/browserify-rails/output20150408-17982-up3cdh" -
Completed 500 Internal Server Error in 796ms

ActionView::Template::Error (Error while running `/Users/lynn/Code/Healthbox/databoxapi/clients/ui/lib/dbx_ui_engine/node_modules/.bin/browseri
fyinc -t reactify --extension=".js.jsx" -r react -r jquery -r dbx_ui_engine/dbx_ui_commonjs -v --list --cachefile="/Users/lynn/Code/Healthbox/d
ataboxapi/tmp/cache/browserify-rails/browserifyinc-cache.json" -o "/Users/lynn/Code/Healthbox/databoxapi/tmp/cache/browserify-rails/output20150
408-17982-up3cdh" -`:

changed files:
/Users/lynn/Code/Healthbox/databoxapi/clients/ui/lib/dbx_ui_engine/app/assets/commonjs/dbx_ui_engine/components/metrics/controller.js.jsx
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: ENOENT, open 'react'
    at Error (native)

Handle .js.erb files?

Can you clarify this line from the Readme? "Serve assets with Sprockets."

I assumed that meant files would be run through Sprockets prior to being bundled by Browserify, but files with a .js.erb extension don't appear to be served via Sprockets.

Sprockets-style requires work fine (//= require whatever) but Browserify-style requires all fail with Cannot find module 'whatever' from .... Is it not possible to have a file processed by Sprockets and Browserify in sequence, or am I just misunderstanding the documentation?

Asset bundle is always named _stream_0.js in the Source Map

It seems that the asset bundle (the file initially loaded from a <script>) is always named _stream_0.js in the Source Map (the fixtures also show this).

Is there a known issue about this, or a reason that you know of? It’d be ❤️ ❤️ ❤️ if it were named the same as the file on disk.

Clarification

Hi there,

This is more of a request for clarification than a question. I'm brand new to Browserify and generally have no idea what I am doing :)

  1. Can I require("foo") in multiple locations, and browserify-rails will only include foo once?
  2. If 1 == "Yes", does it matter where the require("foo") happens? (i.e. does it make a difference if it is inside or outside of a function?)
  3. If I am mixing & matching modules and standard Rails javascript organization, can I require("bar") in one location, and then //= require bar in another, and I will only get the package once?

Thanks!

reloading asset files if dependency in node_modules changes

Hi, I am just wondering if this is the intended behaviour or if my setup is wrong.

I have put my application specific shared files in node_modules (as advised here https://github.com/substack/browserify-handbook#node_modules)

This is so I don't have to use relative paths to require them.

app/asset/javascripts/test.js

var test = require('test-app')
console.log(test)

node_modules/test-app/index.js

exports = 'this should change'

I can change node_modules/test-app/index.js, but only when I change app/asset/javascript/test.js after the fact does the change show up in the console.

I tried
config.browserify_rails.evaluate_node_modules = true
but this seems to have no effect.

This is a pain because a lot of the time I am working on the test-app module. Is there a better way to achieve this?

options for compiling vs options for checking dependencies

It so happens that browserify-rails uses the same CLI options for checking the dependencies and actually compiling the file.

  • -d is not necessary when checking dependencies
  • --list is not necessary when compiling the end file

I noticed the issue since I was trying to use minifyify as a plugin. I added the CLI arguments for it. The plugin crashes since it doesn't get the source map when browserify-rails is checking for dependencies (I honestly have no idea why). I modified the gem locally to add compile_commandline_options that are only applied when run_browserify is called for compilation. It's most likely a wrong implementation, it was only meant to be a test. It worked.

I'm not sure how best to do the distinction. Some transforms like CoffeeScript compilation are quite useful every time browserify will be ran within the browserify-rails process (or else it might crash).

Cannot get multiple bundles to work

I'm trying to split my application code and the libraries it uses (React, lodash, and more) into different bundles in order to make the bundle compile faster (right now it takes around 20 seconds every time, which is hard to deal with).

Maybe I don't understand the concept, but I cannot get the mechanism to work.

To start, I have the following structure for my JS:

app/assets/javascripts/
  application.js
  dependencies.js

Plus of course multiple other files and subdirectories that contain my application's code. All of them are required (either directly or indirectly) from application.js.

As I could not understand whether or not it's the correct way to do it, I created dependencies.js with the following content:

require("lodash");
require("react");

It basically requires all of the libraries I want to become external.

I then created config/browserify.yml:

javascript:
  dependencies:
    require:
      - lodash
      - react

  application:
    external:
      - lodash
      - react

As I understand it, the dependencies.js file should be requiring all of those libraries and marking them as externally accessible ones, while the application.js file should be assuming the presence of the external dependencies and not including them within itself.

Looking at the output when I request /assets/dependencies.js in my browser, the generated bundle begins with require=..., which should be the right behaviour (since I can now call that function from my other bundle and get those libraries that I need).

The problem is that my application.js bundle, which still requires react and lodash all over the place, also includes the source of those libraries. That's not the expected behaviour, as it should now just expect them to be there rather than bundling them.

Would you be able to tell me what I am doing wrong?


As an aside, I would like to know if the file dependencies.js has to be situated at the top level. How would I go about putting it in a subdirectory of app/assets/javascripts (e.g. ./system) and referencing it in browserify.yml

Ignore browserified sources

The current approach wraps all scripts containing module.exports. In some cases I'm finding this ends up hiding libraries that were previously browserified or written as umd modules.

Sprockets-required files don't share their required modules

It appears that when you use //= require to include browserify-able files, these files don't share their modules. For example:

//= require modules/a
//= require modules/b
// Both modules have: var x = require("../lib/counter");

In the compiled file, the counter library will be written twice. I know there are documented ways around this but it seems a huge burden to rely on this YAML file, especially in a large project with many files and multiple shared dependencies.

The problem I've seen reported is mostly to do with file bloat — you don't want large libraries to be defined multiple times in one file. But in some cases, it's actually catastrophic to initialize the same library several times on the same page. For example, React will refuse to work unless it's give a solitary definition/initialization.

I built a reduced test case and documented the issue here: https://github.com/mattwondra/browserify-rails-issue

Ideally, the postprocessor in this gem should be able to share the module definitions across //= require-d files. But if this is overly difficult or impossible given the Asset Pipeline's tools, may I suggest an optional strict_mode config flag that prevents you from //= require-ing Browserify-able files?

I built a local prototype and would be happy to submit a pull request. When this mode is set, the asset precompile fails if it detects that a //= require-d file needs to be Browserified. The error message tells you to require(...) them instead.

Thanks for the consideration!

File name too long under JRuby

I have a Rails app that this was working in with Ruby 2.1.2, but when running it on JRuby (1.7.15), I get the following error:

IOError in Home#index
Showing /Users/me/code/MyApp/app/views/layouts/home.html.haml where line #24 raised:

Cannot run program "{"NODE_PATH"=>"/Users/me/code/MyApp/app/assets/images:/Users/me/code/MyApp/app/assets/javascripts:/Users/me/code/MyApp/app/assets/stylesheets:/Users/me/code/MyApp/vendor/assets/d3_javascripts:/Users/me/code/MyApp/vendor/assets/react_javascripts:/Users/me/code/MyApp/vendor/assets/stx_images:/Users/me/code/MyApp/vendor/assets/stx_javascripts:/Users/me/code/MyApp/vendor/assets/stx_stylesheets:/Users/me/code/MyApp/vendor/assets/vertx_javascripts:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/chartkick-1.3.0/app/assets/javascripts:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/font-awesome-rails-4.1.0.0/app/assets/fonts:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/font-awesome-rails-4.1.0.0/app/assets/stylesheets:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/foundation-rails-5.2.3.0/vendor/assets/javascripts:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/foundation-rails-5.2.3.0/vendor/assets/stylesheets:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/jquery-ui-rails-4.2.1/app/assets/images:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/jquery-ui-rails-4.2.1/app/assets/javascripts:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/jquery-ui-rails-4.2.1/app/assets/stylesheets:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/jquery-rails-3.1.0/vendor/assets/javascripts:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/gritter-1.1.0/vendor/assets/images:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/gritter-1.1.0/vendor/assets/javascripts:/Users/me/code/MyApp/vendor/bundle/jruby/1.9/gems/gritter-1.1.0/vendor/assets/stylesheets"}" (in directory "/Users/me/code/MyApp"): error=63, File name too long
  (in /Users/me/code/MyApp/app/assets/javascripts/application.js)

Is this just me? Does it otherwise work in JRuby?

Newbie questions

Hi!

I'm one of frontend devs in a Rails project. I'm considering migrating our JS code to Browserify.

First of all, thank you for your browserify-rails project. I was expecting a lot of issues with setting up Browserify, possibly preventing from using it at all. But i tried browserify-rails and it just worked, that's amazing! Thank you. ^_^

  1. We're using the jquery-rails and jquery-ui-rails gems. They provide various assets served from a correct location. Requiring jquery with CommonJS was remarkably simple. It just worked.

But as for jquery-ui, it does not seem to be Browserified. I found it impossible to require it. I found two possible solutions, but neither seems to be suitable:

  • There's jquery-ui-browserify, but it's an NPM package. Some Rails internals (e. g. Active Admin) depend on the jquery-ui-rails gem, i can't just swap it for a local file.
  • There's something called browserify-shim and browserify-rails seems to support it. But browserify-shim requires providing relative paths to shimmed files, and as jquery-ui-rails is served from a Ruby gem, the path cannot be hardcoded.

Question 1: Is there a way to use jquery-ui-rails with browserify-rails? If yes, how? If no, how can i work around this issue?

  1. Project owners did not provide us with a time window for refactoring. We will have to refactor while working on new features in the existing codebase. This means we're unable to turn all our code into CommonJS modules at once. We will have to do it little by little.

But when i tested that approach, i ran into an issue of bloated file size.

I created two files: foo.js and bar.js and required them into application.js via Sprockets. That mimics our current project organization. Now, if i do $ = require('jquery'); in either file, this will result into Rails serving jQuery three times: one for either file and one from the jquery-rails gem.

Question 2: how do i have Rails serve only one jQuery?

  1. I thought of a solution in case both questions are unsolvable: use global jQuery and jQuery UI and browserify the rest.

But the issue of served duplicates still exists.

And there's another problem. We organize our JS code in jQuery UI Widget Factory widgets. In other words, most of our JS is wrapped into $.widget('foo', { /*...*/ });. I suspect that browserifying those while keeping jQuery in global scope is useless: the result will not be modular.

Question 3: is that so? Any ways to work it around?

is there a way to disable or fix source maps?

The docs state that including all the asset paths breaks source maps. Does that mean that source maps don't work at all?

Is there a way to just disable them? In development mode, I'd be fine with just seeing the line that caused the problem and figuring out myself where it came from. Right now it maps all errors to a third-party source file.

No easy way to provide for using browserify in a mountable engine / gem but not the host

I'm using browserify-rails in my gem, and it forces the parent to use it as well with the default paths. In the in the case that the host app doesn't use it or has a non-default configuration, it may become tricky.

Here's my solution -- engine injects an initializer that does this:
app.config.browserify_rails.paths = []
app.config.browserify_rails.paths << lambda { |p| p.start_with?(Engine.root.join("app").to_s) }

There's no way for me to create a gem or engine using browserify-rails that an arbitrary app can mount, since my initializer for configuring browserify-rails is going to depend on whether the parent uses it as well, and AFAIK there's no way to create that conditional.

Perhaps this could be fixed by making all path additions explicit? If there's a way to do it in my engine, I'd be happy for the suggestion.

Escape spaces in Bundler and Rails root pathnames

rake test fails when Bundler.root has a space in the pathname, because spaces aren't properly escaped. rails_path() in browserify_processor.rb should also return an escaped path string.

To reproduce, just clone this repo into a folder with a space in the name and watch rake test fail all its test cases.

I'm having some success using Shellwords to escape path names, but I'm new to Ruby/Rails and still am getting 13 failures with escaped strings.

Trouble with multiple bundles

I'm having trouble creating a multiple bundle setup.

Here's my config/browserify.yml:

javascript:
  application:
    require:
      - jquery
      - lodash
  pages/online:
    external:
      - jquery
      - lodash

Using a require('jquery') inside of pages/online.js gives the following error:

 Uncaught Error: Cannot find module 'tpyseH'

Cannot find module error, due to missing semicolon

Took me a while to track this one down and still don't have a great grasp on it.

I was getting the error Uncaught Error: Cannot find module 'function () {}' and after digging around noticed it looked like there were two functions calls stacked back to back. Throwing a trailing semicolon onto the end of the browserify output fixed things:

def browserify
  run_browserify(options) + ";"
end

I'll try to reduce it to a test case but wanted to throw this out there in case anyone else is running into the same issue. These are coffeescript files so I'm not sure if it's a browserify or coffeeify issue.

Warbler/Jruby with `config.assets.initialize_on_precompile = false` causes assets:precompile to skip browserify

Title says it all, really.

Our setup requires us to bundle up our app into a jRuby war. We've got a build script that does the housekeeping for us, including asset precomplilation with the following command:

jruby -S bundle exec rake assets:precompile

In the application.rb, we have config.assets.initialize_on_precompile = false. If I set it to 'true,' the rake command attempts to connect to a non-existent database (our build server has no active DB).

The problem is, that skips the initializer for browserify-rails, which means our production assets can't utilize the require statements.

Is there a workaround for this situation?

Can't get it working with precompiled assets

Everything works beautifully in my development env without asset precompilation, but as soon as I do rake assets:precompile, all pages give me require is undefined and none of the Browserify wrapper code is present inside my public/assets js files

I've tried every application.rb config option listed in the readme, and I've tried tweaking my config.assets.precompile to have every file in /app get precompiled. No dice. I've also followd all the steps here: http://ryochikazawa.com/2015/01/30/heroku-with-browserify-rails.html

I'm using rails 3.2.18, sprockets 2.2.3

Not sure how & where to troubleshoot this. Have messed with browserify_processor.rb a bunch, but my understanding of Tilt is limited

What to do about jQuery / jQuery UI as gems?

So a lot of people use the gems for jQuery and jQuery UI. Some use gems that depend on those gems. So the question becomes: what is the ideal way to handle this? Can we avoid duplicate jQuery / jQuery UI? If so, how?

Require doesn't seem to be working

I'm trying to use non-string literal requires in my code. I've added config/browserify.yml:

javascript:
  application:
    require:
      - routes/route_a/sub_route.js

In my codebase, I have a file called application.js which requires a file called router.js. This file, in turn, contains calls to require looped over a list of available routes.

Since in Browserify, require won't work with anything except a string literal, this means I need to somehow make it aware that these files exist, and as far as I know that should be possible using the --require option.

Judging from the output in my console, browserify-rails doesn't seem to pass the --require argument at all when compiling my code.

Is there something wrong in the way I'm doing this, or is it not working correctly?


In the end (if this issue gets resolved), I would like to end up with something like:

javascript:
  application:
    require:
      - routes/**/*.js

This is because I'd like to avoid having to specify every single script that's present in my routes tree here. Is that possible?

Support for Browserify 5.10?

2 days ago I spent a while trying to track down an issue where, no matter what I'd do, browserify would keep throwing exceptions. It turns out I had installed version 5.10 without realizing that it's not supported. I'm just wondering if and when this new version will be supported by browserify-rails.

EMFILE error on OS X (exceeding the open file limit) -- upstream issue, please read for workaround

Handle this error in a nicer way:

Error while running `/Users/example/my_repo/my_rails/./node_modules/.bin/browserify -d --list -`:


events.js:72
       throw er; // Unhandled 'error' event
             ^
Error: EMFILE, open '/Users/example/my_repo/my_rails/package.json'

 (in /Users/example/my_repo/my_rails/app/assets/javascripts/some.js)

The solution is to use ulimit to increase the open file limit: browserify/browserify#431.

Transforms: es6

I am probably missing something obvious here, but I can't seem to get browserify-rails to recognize es6 files:

I have added es6ify to my package.json
and
config.browserify_rails.commandline_options = "-t es6ify --extension=\".js.es6\"" to my application.rb

But it seems to not bother applying the transform to either required .js.es6 files or ones directly hit by my browser. It just ends up with a parsing error because it doesn't know what 'let' is.

Any suggestions?

Remove NPM dependency

In a lot of Rails projects, NPM is an added dependency. Is it possible to move the JS required to something ruby based? This way there's not as much complexity.

Configuration of command line arguments and regular browserify versus browserify --list

We pass the command line options down to both the call to browserify and the call to browserify --list however I noticed with some transforms, there are errors when combined with the list call. We need to look into this more -- one solution might be to have two configuration options but that is messy. It might be a good short term approach if we can't figure out what options should be used in conjunction with list.

Consecutively `//= require`-d modules cause runtime error

I noticed that when you use Sprockets to import consecutive modules, there is a runtime error in the compiled script. I believe it has to do with a missing semicolon between the module definitions when the whole thing is concatenated. e.g.:

//= require "modules/a"
//= require "modules/b"
//= require "modules/c"
// These modules all contain require("..") and module.exports

When compiled you get this runtime error:

Uncaught Error: Cannot find module 'function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}'

When you view the concatenated file, it looks like the root issue is caused by the modules being squished up next to each other without any whitespace or a semicolon in-between, a la:

/* ... end of first module ... */ ,{},[2])(function e(t,n,r){ /* ... start of second module ... */

It looks like this can be solved by simply inserting a semicolon between the modules:

/* ... end of first module ... */ ,{},[2]);(function e(t,n,r){ /* ... start of second module ... */

I built a reduced test case and documented the issue here: https://github.com/mattwondra/browserify-rails-issue

Error messages don't give the cause of the issue straight away

Whenever I make a mistake and Browserify can't bundle my code, the error that appears on the page gives me no relevant information at first glance.

browserifyrails__browserifyerror at _home-1 copy

I can only ever see up to the throw er; part, which is always part of any browserify-rails exception.

The real cause of the error comes after that, and I can only see it by going to the command line:

Error: Cannot find module 'private-components' from '/apps/my-website/app/assets/javascripts/system'

Would it not be possible for browserify-rails to put this line at the forefront of the exception?

Unable to use browserify.yml and commandline_options together

I'm trying to split my bundle into two files: deps and application.

Here is my deps file:

//= require react_ujs

require('react');
require('react-router');
require('react-bootstrap');

And here is my application file:

require('routes/app');

Here is my commandline_options setting:

    config.browserify_rails.commandline_options = [
      '-t reactify --extension=".js.jsx"'
    ]

Here is my browserify.yml:

javascript:
  deps:
    require:
      - 'react'
      - 'react-bootstrap'
      - 'react-router'
  application:
    external:
      - 'react'
      - 'react-bootstrap'
      - 'react-router'

Here is the output:

Processing by LandingController#index as HTML
  Rendered landing/index.html.haml within layouts/application (2.3ms)
Browserify: /Users/lynn/Code/Trash/circuit-slave/node_modules/.bin/browserifyinc -t reactify --extension=".js.jsx" --list --cachefile="/Users/lynn/Code/Trash/circuit-slave/tmp/cache/browserify-rails/browserifyinc-cache.json" -o "/Users/lynn/Code/Trash/circuit-slave/tmp/cache/browserify-rails/output20150328-83686-dx9tp9" -
Browserify: /Users/lynn/Code/Trash/circuit-slave/node_modules/.bin/browserifyinc -t reactify --extension=".js.jsx"  --require react --require react-bootstrap --require react-router --cachefile="/Users/lynn/Code/Trash/circuit-slave/tmp/cache/browserify-rails/browserifyinc-cache.json" -o "/Users/lynn/Code/Trash/circuit-slave/tmp/cache/browserify-rails/output20150328-83686-1vlairk" -
Browserify: /Users/lynn/Code/Trash/circuit-slave/node_modules/.bin/browserifyinc -t reactify --extension=".js.jsx" --list --cachefile="/Users/lynn/Code/Trash/circuit-slave/tmp/cache/browserify-rails/browserifyinc-cache.json" -o "/Users/lynn/Code/Trash/circuit-slave/tmp/cache/browserify-rails/output20150328-83686-1n3gaiq" -

So it doesn't look like the external options from the browserify.yml file are being sent to browserify.

When I remove the commandline_options setting, the require and external options are passed to browserify, but obviously the reactify transform doesn't run and the build fails.

I've also tried adding a transform option to the browserify.yml file like this:

javascript:
  deps:
    require:
      - 'react'
      - 'react-bootstrap'
      - 'react-router'
  application:
    external:
      - 'react'
      - 'react-bootstrap'
      - 'react-router'
    transform:
      - '[reactify --extension=.js.jsx]'

But the transform doesn't run and the build fails.

Please let me know if I'm doing something wrong here.

When I tried to debug this I made it to this line. I was expecting the get_granular_config method to return the configuration defined in the browserify.yml file, but the logical_path value was always nil so get_granular_config always returned nil.

How are package upgrades handled?

If I upgrade a package (ie update version in package.json and run npm install), will all the files that require it get recompiled automatically?

Just tried using npm link to simulate this and it doesn't look like dependencies get recompiled.

Stale cache breaks browserify-inc?

This is a weird one and I'm not convinced it's specifically a browserify-rails issue, but 1) I can't reproduce it outside of browserify-rails and 2) it doesn't happen if I disable browserify-incremental, so my first thought is that it has to do with how that's implemented here.

Whenever I modify any JS source, I get a BrowserifyRails::BrowserifyError on the next pageload pointing to the following error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, open 'foo'

where foo is whatever the first require in my application happens to be.

Here's a test repo: https://github.com/joshfrench/browserify-rails-demo

To reproduce:

  1. git clone && bundle install && npm install.
  2. Start Rails server and visit /.
  3. Modify application.js in some way. (It's not sufficient to just resave and change the mtime; the source actually has to differ from what's cached by browserify-inc.)
  4. Reload page. This is where I experience the error.

Here's what's interesting:

  1. If I drop into the Rails console at the error and re-run the underlying browserify-inc command (via Open3) it succeeds if I modify the arguments.
  2. There doesn't seem to be one specific argument that's causing this; rather, any modification is sufficient to fix the problem. If I remove the --cachefile option from the browserify-inc command, it works. If I remove the chdir arg to Open3, it works.
  3. If I modify the gem source ahead of time with either of those edits, I still get the error.
  4. After modifying the gem source, If I drop into the Rails console at the error and re-run the browserify-inc command in its original, unmodified form it works again.
  5. Reverting application.js so that it matches what browserify-inc has cached will make the error go away.
  6. In other words, it looks as if whenever the cachefile disagrees with what's being served, the command always fails on its initial invocation. Re-invoking it in a different form makes it succeed again.

I'm pretty stumped, and I've been unable to isolate this outside of Rails just using browserify-incremental on its own so I thought I'd start here and see if anyone has any thoughts. Thanks!

when precompiling, module IDs are absolute server paths

Maybe I'm missing an obvious configuration option, but it seems when I precompile assets that the module IDs are the absolute file paths of the files on the server that builds the assets.

Is there any way to change them to be numeric, which I thought was the browserify default, or just paths relative to RAILS_ROOT?

For security reasons, I wouldn't be allowed to deploy public files with those paths on them.

Requiring a sprockets-preprocessed file

I'm trying to get sprockets to preprocess a file that contains a directive so that when I require() using browserify, it will contain the generated JavaScript.

This is my setup (within app/assets/javascripts):

system/
  rails_routes.js
application.js

application.js is the main file, and it starts the rest of the application. I would like to be able to do something like

var rr = require("./system/rails_routes.js");

in it.

In system/react_routes.js, I have the following:

//= require js-routes

console.log("Does this work?");

As an aside, I also configured js-routes to place the output in an object called module.exports, so to comply with the CommonJS model, as described in railsware/js-routes#121.

The only issue is that when I look at the generated bundle, the sprockets directive is still there and has not been expanded.

Is there a way to get this to work? What is the correct way to have sprockets preprocess a file before bundling it with browserify-rails?

testing with teaspoon and mocha

I'm now trying to do testing with the https://github.com/modeset/teaspoon test runner and http://mochajs.org/

// /spec/javascripts/example_spec.js
//= require jquery
//= require expect
describe('My great feature', function() {

  it('will change the world', function() {
    expect(true).to.be(true)
    expect(jQuery).to.not.be(undefined)
  })
})

I opted to use the sprockets style require //= require foo because var jQuery = require('jquery') here returns

ReferenceError: Can't find variable: require
  # example_spec-7c5082a9c51145554112cd53b17714da.js:1

But the sprockets style works fine for jquery. It's now choking on the expect npm module. I have verified that it's available in node_modules. Is the problem that it relies on node's assert module? https://www.npmjs.com/package/expect

There should be a way to integrate both as here https://github.com/modeset/teaspoon/wiki/RequireJS-with-Teaspoon are instructions for integrating teaspoon with requirejs-rails gem.

error EOFError

I'm getting the following stacktrace

[2015-03-24 03:14:26] INFO  WEBrick 1.3.1
[2015-03-24 03:14:26] INFO  ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
[2015-03-24 03:14:26] INFO  WEBrick::HTTPServer#start: pid=6673 port=3000
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms state=ready

source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=11ms state=active

Started GET "/" for ::1 at 2015-03-24 03:14:29 -0700
  ActiveRecord::SchemaMigration Load (0.5ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by HomesController#index as HTML
  Rendered homes/index.html.erb within layouts/application (2.6ms)
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=1003ms state=active
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=2107ms state=active
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=3040ms state=active
  Rendered application/_flashes.html.erb (0.9ms)
Browserify: /Users/harrymoreno/programming/teamrickharry/hermes_dragon/node_modules/.bin/browserifyinc -t [reactify --es6 --everything] --list --cachefile="/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/cache/browserify-rails/browserifyinc-cache.json" -o "/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/cache/browserify-rails/output20150324-6673-vs7e28" -
Browserify: /Users/harrymoreno/programming/teamrickharry/hermes_dragon/node_modules/.bin/browserifyinc -t [reactify --es6 --everything] --list --cachefile="/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/cache/browserify-rails/browserifyinc-cache.json" -o "/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/cache/browserify-rails/output20150324-6673-1d3n31j" -
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=4022ms state=active
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=5004ms state=active
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=6005ms state=active
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=7002ms state=active
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=8004ms state=active
Browserify: /Users/harrymoreno/programming/teamrickharry/hermes_dragon/node_modules/.bin/browserifyinc -t [reactify --es6 --everything] --cachefile="/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/cache/browserify-rails/browserifyinc-cache.json" -o "/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/cache/browserify-rails/output20150324-6673-sn6gre" -
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=9001ms state=active
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=10002ms state=timed_out
  Rendered application/_javascript.html.erb (9425.4ms)
Completed 500 Internal Server Error in 12616ms
** [Airbrake] Notice was not sent due to configuration:
  Environment Monitored? false
  API key set? false

Rack::Timeout::RequestTimeoutError (Request ran for longer than 10000ms
  (in /Users/harrymoreno/programming/teamrickharry/hermes_dragon/app/assets/javascripts/client.js)):
  app/views/application/_javascript.html.erb:1:in `_app_views_application__javascript_html_erb___1462272387560998950_70235651355680'
  app/views/layouts/application.html.erb:29:in `_app_views_layouts_application_html_erb___294586722230227674_70235644546600'


  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (14.4ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.4ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (70.4ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (0.6ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.6ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.7ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.5ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb within layouts/javascript (46.2ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb within layouts/javascript (0.6ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.6ms)
  Rendered /Users/harrymoreno/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (104.1ms)
source=rack-timeout id=50ea1f9594a8edcb4d3674c5bb5ae3b8 timeout=10000ms service=13336ms state=completed

Any ideas what might be causing it? My code was working before and now I have no clue what went wrong. I'm using the reactify transform. Here's a gist

No CHANGELOG

Please add a CHANGELOG.md or similar and make it part of the gemspec so that users can easily see what's new after a bundle update.

How to get gem to play nicely with react-rails?

I have a .js.jsx file in my assets that is not being required correctly by browserify-rails. https://github.com/reactjs/react-rails#jsx performs on the assets:precompile step. When does browserify-rails fire?

directory structure

▾ app/
  ▾ assets/
    ▸ images/
    ▾ javascripts/
      ▾ components/
          .gitkeep
          logout_form.js.jsx
          navbar.js.jsx
        application.js
    ▸ stylesheets/
/* apps/assets/javascripts/application.js */
//= require jquery
//= require jquery-ujs
//= require react
//= require react_ujs
//= require react-bootstrap
//= require socket.io-client/socket.io.js
//= require_tree .

var logoutForm = require('./components/logout_form.js.jsx');
var navbar = require('./components/navbar.js.jsx');
var debug = require('debug')('hermesDragon:client');

debug('loaded npm module using browserify!');

error


BrowserifyRails::BrowserifyError in Homes#index

Showing /Users/harrymoreno/programming/teamrickharry/hermes_dragon/app/views/application/_javascript.html.erb where line #1 raised:

Error while running `/Users/harrymoreno/programming/teamrickharry/hermes_dragon/node_modules/.bin/browserifyinc -d --cachefile="/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/browserify-rails/browserifyinc-cache.json" -o "/Users/harrymoreno/programming/teamrickharry/hermes_dragon/tmp/browserify-rails/output20150226-70503-ct958f" -`:


/Users/harrymoreno/programming/teamrickharry/hermes_dragon/app/assets/javascripts/components/navbar.js.jsx:39
        <LogoutForm
        ^
ParseError: Unexpected token

  (in /Users/harrymoreno/programming/teamrickharry/hermes_dragon/app/assets/javascripts/application.js)

Extracted source (around line #1):

1
2
3
4
5
6




<%= javascript_include_tag :application %>

<%= javascript_tag do %>
  <%= yield :javascript %>
<% end %>


Trace of template inclusion: app/views/layouts/application.html.erb

Rails.root: /Users/harrymoreno/programming/teamrickharry/hermes_dragon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.