I have the most frustrating issue on my rails 7 app. None of my bootstrap drop downs(dropdown buttons or dropdown nav) will work, they add a hash to my url.
I am using the jumpstart template https://github.com/excid3/jumpstart
For instance when I click the drop down in my nav menu it adds a hash to the url and the dropdown wont open.
<li class="nav-item dropdown">
<%= link_to "#", id: "navbar-dropdown", class: "nav-link text-dark dropdown-toggle", data: { turbo: "false", target: "nav-account-dropdown", bs_toggle: "dropdown" }, aria: { haspopup: true, expanded: false } do %>
<%= image_tag avatar_path(current_user, size: 40), height: 20, width: 20, class: "rounded" %>
<% end %>
<div id="nav-account-dropdown" class="dropdown-menu dropdown-menu-end" aria-labelledby="navbar-dropdown">
<%= link_to "Settings", edit_user_registration_path, class: "dropdown-item" %>
<% if current_user.admin? && respond_to?(:madmin_root_path) %>
<div class="dropdown-divider"></div>
<%= link_to "Admin Area", madmin_root_path, class: "dropdown-item" %>
<% end %>
<div class="dropdown-divider"></div>
<%= button_to "Logout", destroy_user_session_path, method: :delete, class: "dropdown-item" %>
</div>
</li>
My application.js
import "#hotwired/turbo-rails"
require("#rails/activestorage").start()
import "trix"
import "#rails/actiontext"
require("local-time").start()
require("#rails/ujs").start()
import './channels/**/*_channel.js'
import "./controllers"
import Rails from '#rails/ujs'
Rails.start()
import * as bootstrap from "bootstrap"
document.addEventListener("turbo:load", () => {
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
})
var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
return new bootstrap.Dropdown(dropdownToggleEl)
})
})
I added
var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
return new bootstrap.Dropdown(dropdownToggleEl)
})
as a work around, but it made no difference.
here is a gif showing what i see when testing, no errors appear in console
https://share.cleanshot.com/UmpcTVppoMQskAIWIpsm
gemfile
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.0.3"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.3"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"
# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
# Use Redis adapter to run Action Cable in production
gem "redis", "~> 4.0"
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
# Use Sass to process CSS
# gem "sassc-rails"
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
end
gem "cssbundling-rails"
gem 'devise', '~> 4.8', '>= 4.8.1'
gem 'devise_invitable', '~> 2.0.0'
gem "friendly_id", "~> 5.4"
gem "jsbundling-rails"
gem "madmin"
gem "name_of_person", "~> 1.1"
gem "noticed", "~> 1.4"
gem "pretender", "~> 0.3.4"
gem "pundit", "~> 2.1"
gem "sidekiq", "~> 6.2"
gem "sitemap_generator", "~> 6.1"
gem "whenever", require: false
gem "responders", github: "heartcombo/responders", branch: "main"
gem "simple_calendar", "~> 2.4"
gem "acts_as_list", "~> 1.0"
gem 'pagy', '~> 5.10'
gem 'pg_search', '~> 2.3', '>= 2.3.6'
gem "pay", "~> 3.0"
gem "google-api-client", require: "google/apis/calendar_v3"
gem 'omniauth-rails_csrf_protection', '~> 1.0', '>= 1.0.1'
gem 'omniauth-google-oauth2', '~> 1.0', '>= 1.0.1'
# To use Stripe, also include:
gem "stripe", "~> 6.0"
yarn list
yarn list v1.22.18
├─ #hotwired/stimulus#3.0.1
├─ #hotwired/turbo-rails#7.1.3
│ ├─ #hotwired/turbo#^7.1.0
│ └─ #rails/actioncable#^7.0
├─ #hotwired/turbo#7.1.0
├─ #popperjs/core#2.11.5
├─ #rails/actioncable#7.0.3
├─ #rails/actiontext#6.0.5
│ └─ #rails/activestorage#^6.0.0
├─ #rails/activestorage#6.0.5
│ └─ spark-md5#^3.0.0
├─ #rails/request.js#0.0.6
├─ #rails/ujs#6.0.5
├─ anymatch#3.1.2
│ ├─ normalize-path#^3.0.0
│ └─ picomatch#^2.0.4
├─ balanced-match#1.0.2
├─ binary-extensions#2.2.0
├─ bootstrap-icons#1.8.3
├─ bootstrap#5.1.3
├─ brace-expansion#1.1.11
│ ├─ balanced-match#^1.0.0
│ └─ concat-map#0.0.1
├─ braces#3.0.2
│ └─ fill-range#^7.0.1
├─ chokidar#3.5.3
│ ├─ anymatch#~3.1.2
│ ├─ braces#~3.0.2
│ ├─ fsevents#~2.3.2
│ ├─ glob-parent#~5.1.2
│ ├─ is-binary-path#~2.1.0
│ ├─ is-glob#~4.0.1
│ ├─ normalize-path#~3.0.0
│ └─ readdirp#~3.6.0
├─ concat-map#0.0.1
├─ esbuild-android-64#0.14.48
├─ esbuild-android-arm64#0.14.48
├─ esbuild-darwin-64#0.14.48
├─ esbuild-darwin-arm64#0.14.48
├─ esbuild-freebsd-64#0.14.48
├─ esbuild-freebsd-arm64#0.14.48
├─ esbuild-linux-32#0.14.48
├─ esbuild-linux-64#0.14.48
├─ esbuild-linux-arm#0.14.48
├─ esbuild-linux-arm64#0.14.48
├─ esbuild-linux-mips64le#0.14.48
├─ esbuild-linux-ppc64le#0.14.48
├─ esbuild-linux-riscv64#0.14.48
├─ esbuild-linux-s390x#0.14.48
├─ esbuild-netbsd-64#0.14.48
├─ esbuild-openbsd-64#0.14.48
├─ esbuild-rails#1.0.3
│ └─ glob#^7.2.0
├─ esbuild-sunos-64#0.14.48
├─ esbuild-windows-32#0.14.48
├─ esbuild-windows-64#0.14.48
├─ esbuild-windows-arm64#0.14.48
├─ esbuild#0.14.48
│ ├─ esbuild-android-64#0.14.48
│ ├─ esbuild-android-arm64#0.14.48
│ ├─ esbuild-darwin-64#0.14.48
│ ├─ esbuild-darwin-arm64#0.14.48
│ ├─ esbuild-freebsd-64#0.14.48
│ ├─ esbuild-freebsd-arm64#0.14.48
│ ├─ esbuild-linux-32#0.14.48
│ ├─ esbuild-linux-64#0.14.48
│ ├─ esbuild-linux-arm#0.14.48
│ ├─ esbuild-linux-arm64#0.14.48
│ ├─ esbuild-linux-mips64le#0.14.48
│ ├─ esbuild-linux-ppc64le#0.14.48
│ ├─ esbuild-linux-riscv64#0.14.48
│ ├─ esbuild-linux-s390x#0.14.48
│ ├─ esbuild-netbsd-64#0.14.48
│ ├─ esbuild-openbsd-64#0.14.48
│ ├─ esbuild-sunos-64#0.14.48
│ ├─ esbuild-windows-32#0.14.48
│ ├─ esbuild-windows-64#0.14.48
│ └─ esbuild-windows-arm64#0.14.48
├─ fill-range#7.0.1
│ └─ to-regex-range#^5.0.1
├─ fs.realpath#1.0.0
├─ fsevents#2.3.2
├─ glob-parent#5.1.2
│ └─ is-glob#^4.0.1
├─ glob#7.2.3
│ ├─ fs.realpath#^1.0.0
│ ├─ inflight#^1.0.4
│ ├─ inherits#2
│ ├─ minimatch#^3.1.1
│ ├─ once#^1.3.0
│ └─ path-is-absolute#^1.0.0
├─ hotkeys-js#3.9.4
├─ immutable#4.1.0
├─ inflight#1.0.6
│ ├─ once#^1.3.0
│ └─ wrappy#1
├─ inherits#2.0.4
├─ is-binary-path#2.1.0
│ └─ binary-extensions#^2.0.0
├─ is-extglob#2.1.1
├─ is-glob#4.0.3
│ └─ is-extglob#^2.1.1
├─ is-number#7.0.0
├─ local-time#2.1.0
├─ lodash.debounce#4.0.8
├─ lodash#4.17.21
├─ minimatch#3.1.2
│ └─ brace-expansion#^1.1.7
├─ normalize-path#3.0.0
├─ once#1.4.0
│ └─ wrappy#1
├─ path-is-absolute#1.0.1
├─ picomatch#2.3.1
├─ readdirp#3.6.0
│ └─ picomatch#^2.2.1
├─ sass#1.53.0
│ ├─ chokidar#>=3.0.0 <4.0.0
│ ├─ immutable#^4.0.0
│ └─ source-map-js#>=0.6.2 <2.0.0
├─ source-map-js#1.0.2
├─ spark-md5#3.0.2
├─ stimulus-clipboard#3.2.0
├─ stimulus-notification#2.0.0
│ └─ stimulus-use#^0.50.0-2
├─ stimulus-rails-autosave#4.0.0
│ └─ lodash.debounce#^4.0.8
├─ stimulus-use#0.50.0
│ └─ hotkeys-js#>=3
├─ to-regex-range#5.0.1
│ └─ is-number#^7.0.0
├─ trix#2.0.0-beta.0
└─ wrappy#1.0.2
Related
I recently updated webpacker, babel, and many other packages on my Rails project so that node-sass would work on the heroku-20 stack, and after enough fiddling webpacker is able to compile and start but when attempting to load any of the pages, Rails attempts to fetch /packs/js/application-44959decf6e2f6f8700f.js when Webpacker shows me it is bundled at /packs/application-17d61f0126c1ef6152fd.js. None of my React JS loads, only the Rails-rendered part shows.
My project is Ruby on Rails 5.2.8 (Ruby 2.7) with #rails/webpacker updated to 5.3.0, Webpack updated to 5.1.0, Node updated to 14.18.1. React version is 16.4.1.
Things I have tried:
npx webpack init
bundle exec rails webpacker:install
copying config files from another app with the same Node/webpack versions and resetting them after getting the same errors
Completely stuck on this, any help is appreciated.
package.json:
{
"name": "xxxxxxxx",
"private": true,
"dependencies": {
"#rails/actioncable": "^6.0.5",
"#rails/webpacker": "5.3.0",
"axios": "^0.17.1",
"babel-loader": "8.1.0",
"#babel/preset-react": "^7.18.6",
"babel-plugin-syntax-dynamic-import": "7.0.0-beta.3",
"babel-plugin-transform-object-rest-spread": "7.0.0-beta.3",
"babel-preset-env": "1.7.0",
"babel-preset-react": "6.24.1",
"compression-webpack-plugin": "^1.1.6",
"css-loader": "^5.1.1",
"file-loader": "^6.1.0",
"immutability-helper": "^2.8.1",
"lodash.groupby": "^4.6.0",
"lodash.snakecase": "^4.1.1",
"nanoid": "^2.1.1",
"sass": "^1.56",
"postcss-loader": "^7.0.1",
"prop-types": "^15.6.0",
"react": "^16.4.1",
"react-animate-height": "^2.0.7",
"react-copy-to-clipboard": "^5.0.1",
"react-datepicker": "^2.8.0",
"react-dom": "^16.2.0",
"react-geosuggest": "^2.9.0",
"react-inlinesvg": "^1.1.7",
"react-select": "^2.4.2",
"react-tagsinput": "^3.19.0",
"react-transition-group": "^2.2.1",
"reactstrap": "^6.5.0",
"sass-loader": "^12.6.0",
"uglifyjs-webpack-plugin": "^1.1.8",
"webpack": "^5.1.0",
"webpack-cli": "^4.10.0",
"webpacker-react": "^0.3.2"
},
"devDependencies": {
"babel-plugin-transform-class-properties": "6.24.1",
"#webpack-cli/serve": "^2.0.0",
"eslint": "4.19.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"webpack-dev-server": "~3"
},
"scripts": {
"eslint": "./node_modules/.bin/eslint --ext .js,.jsx ./app/javascript"
},
"engines": {
"node": "14.18.x"
}
}
webpack.config.js
const path = require("path");
const isProduction = process.env.NODE_ENV == "production";
const config = {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
},
devServer: {
open: true,
host: "localhost",
port: 3035
},
};
module.exports = () => {
if (isProduction) {
config.mode = "production";
} else {
config.mode = "development";
}
return config;
};
config/webpacker.yml
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .jsx
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
.babelrc
{
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"syntax-dynamic-import",
"transform-object-rest-spread",
"#babel/plugin-proposal-object-rest-spread",
[
"transform-class-properties",
{
"spec": true
}
]
]
}
Gemfile
source 'https://rubygems.org'
ruby '~> 2.7.6'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.8'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.2.3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'letter_opener', '>= 1.8.1'
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'activerecord-import'
gem 'active_model_serializers'
gem 'geocoder'
gem 'searchkick', '~> 5.0.3'
gem 'devise'
gem 'addressable'
gem 'parallel'
gem 'oj'
gem 'webpacker', '~> 4.3.0'
gem 'webpacker-react', '~> 0.3.2'
gem 'bootstrap', '~> 4.0.0'
gem 'kaminari'
gem 'paranoia', '~> 2.2'
gem 'cocoon'
gem 'jquery-rails'
gem 'select2-rails'
# gem 'select2-rails-latest' # update select2 to make dropdowns case-insensitive
gem 'attribute_normalizer'
gem 'aws-sdk-s3', '~> 1'
gem 'aasm'
gem 'bunny'
gem 'kt-paperclip', '~> 6.4.2'
gem 'font-awesome-rails'
gem 'lograge'
gem 'rollbar'
gem 'httparty'
gem 'restforce'
gem 'sidekiq'
gem 'postmark-rails'
gem "mimemagic", path: 'vendor/gems/mimemagic-0.3.2'
gem 'paper_trail'
gem 'pry'
gem 'elasticsearch'
group :test do
gem 'timecop'
gem 'climate_control'
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails'
gem 'foreman'
gem "factory_bot_rails"
gem 'faker'
gem 'capybara'
gem 'database_cleaner-active_record'
gem 'selenium-webdriver', '~> 3.14'
gem 'capybara-screenshot'
gem 'rubocop', '~> 1.29', require: false
gem 'figaro'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'pry-rails'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'rspec_junit_formatter'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Procfile.dev
web: bin/rails server -p 3002
webpack: yarn run webpack serve --mode=development
worker: bundle exec sidekiq -C config/sidekiq.yml
es: bin/elasticsearch-8.2.3/bin/elasticsearch
Solved by switching to bin/webpack-dev-server instead of yarn run webpack serve in Procfile.dev. I then had to copy some intricate configuration files in config/webpack/ from another project with the same setup, then configure all of the loaders.
I can't push my code to heroku but it works in local.
When i make rake assets:precompile in terminal, i've this answer:
rake aborted!
Sprockets::FileNotFound: couldn't find file 'turbolinks' with type 'application/javascript' I don't want use Sprockets anymore
I tryed this: https://www.innoq.com/en/blog/rails-custom-elements-with-turbolinks-webpack/
but when i make :
class ApplicationController < ActionController::Base
include Turbolinks::Redirection
# ...
end
I've this error uninitialized constant ApplicationController::Turbolinks from error consol
My application.js from app/javascript/packs/
import Turbolinks from 'turbolinks'
Turbolinks.start()
import '../css/application.scss'
import 'bootstrap'
My package.json
{
"name": "**********",
"private": true,
"dependencies": {
"#rails/webpacker": "3.5",
"bootstrap": "^4.2.1",
"jquery": "^3.3.1",
"popper.js": "^1.14.6",
"turbolinks": "^5.2.0"
},
"devDependencies": {
"webpack-dev-server": "2.11.2"
},
"version": "1.0.0",
"main": "index.js",
"repository": "git#github.com:******/*************.git",
"author": "******* <******#email.com>",
"license": "MIT"
}
My Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'webpacker'
gem 'jbuilder', '~> 2.5'
gem 'simple_form'
gem 'postmark-rails'
gem 'cloudinary'
gem 'dotenv-rails', groups: [:development, :test]
gem 'rails_admin'
gem 'turbolinks', require: false
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'better_errors'
gem 'binding_of_caller'
gem 'letter_opener'
end
group :test do
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
My webpacker.yml from app/config/webpack/
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
My application.html.erb from app/views/layouts
<%= javascript_pack_tag 'application', 'data-turbolinks-eval': false, defer: true %>
<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload', defer: true %>
For me the problem lied in application.js. After creating a brand new Ruby on Rails app my application.js header looked like this:
Before
//= require turbolinks
//= require_tree .
The //=require turbolinks seemed to be causing the problem because I never installed turbolinks or anything of the sort. Removing this line fixed the issue for me:
After
//= require_tree .
I am trying to run a rails app that uses react and webpacker. All of the node_modules are installed through yarn.
When I boot up the local server using foreman, I get the error:
Errno::EPERM - Operation not permitted - /private/var/db/ConfigurationProfiles/Store:
yarn.lock:
"#rails/webpacker#3.4":
version "3.4.3"
resolved "https://registry.yarnpkg.com/#rails/webpacker/-/webpacker-3.4.3.tgz#496a5d49bea8856db20b212d2727a4b43b281dd9"
dependencies:
babel-core "^6.26.0"
babel-loader "^7.1.2"
babel-plugin-syntax-dynamic-import "^6.18.0"
babel-plugin-transform-class-properties "^6.24.1"
babel-plugin-transform-object-rest-spread "^6.26.0"
babel-polyfill "^6.26.0"
babel-preset-env "^1.6.1"
case-sensitive-paths-webpack-plugin "^2.1.1"
compression-webpack-plugin "^1.1.10"
css-loader "^0.28.9"
extract-text-webpack-plugin "^3.0.2"
file-loader "^1.1.6"
glob "^7.1.2"
js-yaml "^3.10.0"
node-sass "^4.7.2"
path-complete-extname "^1.0.0"
postcss-cssnext "^3.1.0"
postcss-import "^11.0.0"
postcss-loader "^2.1.0"
sass-loader "^6.0.6"
style-loader "^0.20.1"
uglifyjs-webpack-plugin "^1.1.8"
webpack "^3.10.0"
webpack-manifest-plugin "^1.3.2"
Package.json:
{
"dependencies": {
"#rails/webpacker": "3.4",
"babel-preset-react": "^6.24.1",
"prop-types": "^15.6.1",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-on-rails": "11.0.2",
"react_ujs": "^2.4.4",
"wallet-address-validator": "^0.1.7"
},
"devDependencies": {
"webpack-dev-server": "2.11.2"
}
}
Gemfile:
source 'https://rubygems.org'
ruby "2.5.0"
gem 'active_model_otp', "~> 1.2"
gem "active_model_serializers", "~> 0.10"
gem 'attr_encrypted', "~> 3.1"
gem 'bcrypt', "~> 3.1"
gem 'bootsnap', "~> 1.1", require: false
gem 'bulma-rails', "~> 0.6"
gem 'devise', "~> 4.4"
gem 'faker', "~> 1.8"
gem 'fast_jsonapi', "~> 1.0"
gem 'font-awesome-sass', '~> 4.0'
gem 'foreman', "~> 0.64"
gem 'hashie', "~> 3.5"
gem 'httparty', "~> 0.16"
gem 'jquery-rails', "~> 4.3"
gem 'mini_racer', platforms: :ruby
gem 'omniauth-google-oauth2', "~> 0.5"
gem 'pg', "~> 1.0"
gem 'puma', "~> 3.11"
gem 'pundit', "~> 1.1"
gem 'rails', '~> 5.2.0'
gem 'rails_admin'
gem "react_on_rails", "11.0.0"
gem 'rqrcode', "~> 0.10"
gem 'sass-rails', "~> 5.0"
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem 'uglifier', "~> 4.1"
gem "webpacker", "~> 3.4"
group :development, :test do
gem 'better_errors', "~> 2.4"
gem 'binding_of_caller', "~> 0.8"
gem 'bullet', "~> 5.7"
gem 'byebug', "~> 10.0"
gem 'listen'
gem 'letter_opener', "~> 1.6"
gem 'meta_request', "~> 0.5"
gem 'spring', "~> 2.0"
gem 'spring-commands-rspec', "~> 1.0"
gem 'web-console', "~> 3.5"
end
group :test do
gem 'factory_bot_rails', "~> 4.8"
end
config/webpacker.yml:
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: ['']
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .jsx
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
bin/webpack:
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= ENV["NODE_ENV"] || "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "rubygems"
require "bundler/setup"
require "webpacker"
require "webpacker/webpack_runner"
Webpacker::WebpackRunner.run(ARGV)
bin/yarn:
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec "yarnpkg", *ARGV
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end
app/javascripts/application.js and app/javascripts/server_rendering.js
var componentRequireContext = require.context("components", true)
var ReactRailsUJS = require("react_ujs")
ReactRailsUJS.useContext(componentRequireContext)
The application hangs up at this line:
<%= javascript_pack_tag 'application' %>
I figured it was a file system issue so I reinstalled macos thinking I might have screwed up permissions with something. I have no idea what is going on.
Just hit the same thing. If you take a look at the stack trace, you'll see it's choking here:
files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
The culprit is in webpacker.yml - you'll need to change resolved_paths: [''] to resolved_paths: [] and your problem should be solved :)
I've pushed gem into github & rubygems, but constants of that gem are not being loaded into rails app. Tried this by loading from multiple sources and results are like this:
rubygems = not loaded
github = not loaded
local path = loaded
Interesting things is that when I load with rubygems/github I can load constants with require 'module/gem_name'
The gemspecs looks fine to me:
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'module/gem_name/version'
Gem::Specification.new do |spec|
spec.name = 'gem_name'
spec.version = Module::GemName::VERSION
spec.authors = ['Mike QWERTY']
spec.email = ['mike.qwerty#gamil.com']
spec.summary = 'some_desc'
spec.homepage = 'https://github.com/mike/gem-name'
spec.license = 'MIT'
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
else
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
end
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.4.0'
spec.add_runtime_dependency 'graphql', '>= 1.6.0'
spec.add_development_dependency 'bundler', '~> 1.14'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
end
And structure is:
lib/module/gem_name/stuff/others.rb
lib/module/gem_name/extras.rb
lib/module/gem_name.rb
Also, I've been working on this gem basing on other gem that has the same module name. But it loads correctly into app, if this matters.
Any ideas on this?
The gem is not autoloading because the main file (gem_name.rb) is not at the root of the lib directory. It is recommended that your Gem adhere to the following structure:
% tree
.
├── gem_name.gemspec
└── lib
├── gem_name
│ └── some_file.rb
│ └── other_file.rb
└── gem_name.rb
Yours has an extra module nesting. In your Rails application.rb you should see Bundler.require(*Rails.groups). What this method does is loop through every Gem in your Gemfile and call require gem_name. This works for Gem's that follow the convention mentioned above. Your gem does not - so the auto require being done by Bundler doesn't find the correct file to use.
See the Ruby Gems Guide for creating your own Gem for a bit more information on proper code organization.
If you don't want to change the structure of your application, either add
require "module/gem_name" in an initializer, or within the Gemfile:
gem "gem_name", require: "module/gem_name"
I bought a theme from here, after I integrated it to my project.
Server raised the error
WARN: tilt autoloading 'less' in a non thread-safe way; explicit require 'less' suggested.
Completed 500 Internal Server Error in 262ms
ActionView::Template::Error (.box-shadow is undefined
(in /Users/hsu-wei-cheng/pixnet_hackathon/website/goood_theme/app/assets/ace-admin-theme/css/less/ace-nav.less)):
2: %html
3: %head
4: %title GooodTheme
5: = stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
6: = javascript_include_tag "application", "data-turbolinks-track" => true
7: / Description, Keywords and Author
8: %meta{content: "Your description", name: "description"}/
app/views/layouts/application.html.haml:5:in `_app_views_layouts_application_html_haml___3827456286267197904_2191503380'
The contents in app/assets/ace-admin-theme/css link
I add two files for including all files under their folder
+++ b/app/assets/ace-admin-theme/css/application.css
## -0,0 +1,3 ##
+/*
+*= require_tree .
+*/
+++ b/app/assets/ace-admin-theme/js/application.js
## -0,0 +1 ##
+//= require_tree .
Edited two files
+++ b/app/assets/javascripts/application.js
## -13,5 +13,6 ##
+//= require_tree ../ace-admin-theme/js
+++ b/app/assets/stylesheets/application.css
+ *= require_tree ../ace-admin-theme/css
config/application.rb
config.assets.paths << Rails.root.join("app", "assets", "lenord-single-page-theme")
config.assets.paths << Rails.root.join("app", "assets", "ace-admin-theme")
The folder structure
.
├── avatars
├── css
│ ├── images
│ │ └── ie6
│ ├── img
│ ├── less
│ │ ├── bootstrap
│ │ └── ext
│ └── uncompressed
├── font
├── images
│ └── gallery
├── img
└── js
├── date-time
│ └── locales
├── flot
├── fuelux
│ └── data
├── jqGrid
│ └── i18n
├── markdown
├── uncompressed
│ ├── date-time
│ │ └── locales
│ ├── flot
│ ├── fuelux
│ │ └── data
│ ├── markdown
│ └── x-editable
└── x-editable
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem "bootstrap-sass", "~> 3.1.1"
gem "therubyracer"
gem "hirb-unicode"
gem "devise"
gem "will_paginate", "~> 3.0"
gem "rspec"
gem "awesome_print", require: "ap"
gem "tinymce-rails"
gem "simple_form"
gem "haml-rails"
gem "pg"
gem "taps"
gem "pry"
gem "pry-remote"
gem "pry-nav"
gem "analytics-ruby"
gem "bcrypt-ruby"
gem "bourbon"
gem "cancan"
group :development do
gem "rspec-rails"
gem "guard-rspec"
end
gem "sunspot_rails"
gem "sunspot_solr"
group :assets do
end
gem "simple-navigation"
gem "simple-navigation-bootstrap"
group :assets do
gem 'less'
end
You might find it easier to add the ace-admin-theme folder to your assets path.
# config/application.rb
config.assets.paths << Rails.root.join("app", "assets", "ace-admin-theme")