Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when using browserify with a Rails Engine #167

Open
lucasprag opened this issue Jun 1, 2016 · 6 comments
Open

Errors when using browserify with a Rails Engine #167

lucasprag opened this issue Jun 1, 2016 · 6 comments

Comments

@lucasprag
Copy link

lucasprag commented Jun 1, 2016

I'm trying to use the browserify with a Rails engine.

I followed the Getting Started but I'm geting the error Uncaught ReferenceError: require is not defined when requiring the Vue npm package.

Any tip?

Thanks =)

@lucasprag lucasprag changed the title Rails Engine? Errors when using browserify with a Rails Engine Jun 1, 2016
@lucasprag
Copy link
Author

I also tried to use a simple knock-knock-jokes wihout success. =/

@lucasprag
Copy link
Author

lucasprag commented Jun 1, 2016

I will commit a example app with the error as soon as possible.

@cymen
Copy link
Member

cymen commented Jun 2, 2016

I think another person was asking about this in the past (searching issues should turn it up). I'm not sure what the issue is but PRs are welcomed if you want to take the time to dive into it. I unfortunately do not know what would cause the issue. It might be worth looking at how the plugins mentioned here:

https://github.com/rails/sprockets-rails

Which would be coffee-rails and sass-rails work. That is, if they work inside an engine.

@lucasprag
Copy link
Author

lucasprag commented Jun 2, 2016

I see, thanks =) I'd love to contribute if there is a real problem with browserify-rails, but I think it's a configuration problem. Maybe I could write some instructions in the readme file.

I found the d7143df#diff-04c6e90faac2675aa89e2176d2eec7d8R151 and I followed the instructions.

First of all I changed the example.rb:

require "example/engine"

module Example
  class << self
    def config
      yield self
    end
  end
end

Then I changed the engine.rb:

require 'sprockets/railtie'
require 'browserify-rails'

module Example
  class Engine < ::Rails::Engine
    isolate_namespace Example

    config.browserify_rails.paths << lambda { |p| p.start_with?(Engine.root.join("app").to_s) }
  end
end

Now the error changed to Unable to run node_modules/.bin/browserify. Ensure you have installed it with npm., but I have installed the browserify with npm install as the readme instructions says.

I created a public example with this error: https://github.com/Lucasosf/example

Can you help me please @cymen ? =)

@lucasprag
Copy link
Author

I finally found the problem.

The gem gets the config from Rails.application.config

There is no need to add configs to the engine.rb:

# lib/example/engine.rb
require 'sprockets/railtie'
require 'browserify-rails'

module Example
  class Engine < ::Rails::Engine
    isolate_namespace Example
  end
end

I just added the node_modules of the engine in the paths of the dummy app:

# test/dummy/config/application.rb
config.browserify_rails.paths << Rails.root.join('../../node_modules')

Now I can use npm packages in my isolated engine.

Thanks =D

Perhaps can I add some instructions of using browserify-rails in an isolated engine?

@cymen
Copy link
Member

cymen commented Jun 6, 2016

@Lucasosf Ah! Interesting. Yes, by all means instructions are very welcomed. You can fork and update the README and do a PR if that works for you. Sorry, I have been away for a bit and missed this thread until now.

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

No branches or pull requests

2 participants