asset pipeline - cannot import component: "require is not defined" when using 'import' or 'require'
See original GitHub issueSteps to reproduce
- make a rails project
- include react-rails in it via the asset-pipeline way
import Component from './Component'
- notice
ReferenceError: require is not defined
Expected behavior
Tell us what should happen
it should just import the component
Actual behavior
Tell us what happens instead
i get ReferenceError: require is not defined
System configuration
Sprockets or Webpacker version: sprockets (3.7.1) / sprockets-rails (3.2.1, 3.2.0)
React-Rails version: react-rails (2.4.3)
Rect_UJS version: don’t know how to find this out
Rails version: Rails 5.0.5
Ruby version: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
-
How can I use react-rails asset pipeline and import components from folders? Currently I just have
assets/javascripts/components/<Component.jsx>
referenced like<%= react_component("Component") %>
, but I’d like to nest them into folders. -
How do I import JS libraries with import instead of putting the browser versions of libraries into
assets/javascripts
and referencing them inapplication.js
?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
If you’re using the default asset pipeline then you need to be importing code the sprockets way. https://guides.rubyonrails.org/asset_pipeline.html#search-paths
You can only use Require and Import when using Webpack/Webpacker
Thanks @RiccardoMargiotta , Yep that’s the answer to this one. Let me know if it needs to be re-opened.