Rails + Webpack: Errno::EPERM at / (Operation Not Permitted) - ruby-on-rails

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 :)

Related

Rails cannot fetch application-xxxxxx.js webpack bundle - 404 error

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.

NameError: Cannot load database configuration: undefined local variable or method `“RAILS_MAX_THREADS”' for main:Object

I have a Ruby on Rails app I've created. It uses Rails for the backend and frontend.
I want to deploy it to Heroku, so I've been following some steps to convert my SQLite database to PostgreSQL.
I got to the point where I need to remove SQLite code from my config/database.yml file and replace it with PostgreSQL specific code.
I've added different versions of PostgreSQL code I've found on tutorials into that file. However, once I have the new code in the file and then run rails db:create I get the below error:
rails aborted!
NameError: Cannot load database configuration:
undefined local variable or method `“RAILS_MAX_THREADS”' for main:Object
(erb):10:in `<main>'
Not sure what to do here. Searched the error and there was like one result for this error which had a solution that didn't work.
Another thing to note is that I recently ran bundle install after adding "pg" to the gemfile, installing PostgreSQL, and deleting gemfile.lock.
My database.yml file:
default: &default
adapter: postgresql
pool: <%= ENV.fetch(“RAILS_MAX_THREADS”) { 5 } %>
timeout: 5000
development:
<<: *default
database: development_nail_the_trail
test:
<<: *default
database: test_nail_the_trail
production:
<<: *default
database: production_nail_the_trail
My gemfile:
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "2.6.1"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "rails", "~> 6.0.3", ">= 6.0.3.4"
# Use sqlite3 as the database for Active Record
gem "pg"
# Use Puma as the app server
gem "puma", "~> 4.1"
# Use SCSS for stylesheets
gem "sass-rails", ">= 6"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem "webpacker", "~> 4.0"
# 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.7"
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.2", require: false
gem "bcrypt", "~> 3.1.7"
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]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem "web-console", ">= 3.3.0"
gem "listen", "~> 3.2"
# 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 "pry", "~> 0.13.1"
gem "pry-rails"
gem "faker"
gem "omniauth", "~> 2.0.4"
gem "omniauth-facebook"
gem "omniauth-rails_csrf_protection", "~> 1.0"
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem "capybara", ">= 2.15"
gem "selenium-webdriver"
# Easy installation and use of web drivers to run system tests with browsers
gem "webdrivers"
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
You have the wrong kind of quote characters here
ENV.fetch(“RAILS_MAX_THREADS”)
It should be
ENV.fetch("RAILS_MAX_THREADS")

Rails Webpacker not finding modules (just upgraded to ROR 6.1)

I've just upgraded to ROR 6.1 from 5.4 and have had to start using Webpacker (just used Sprockets before). I've been through the Rails upgrade wizard and installed up-to-date packages through yarn, but can't get Webpacker working.
Whenever I run 'bin/webpack-dev-server', I get multiple error messages for each module saying this:
ERROR in ./app/javascript/packs/application.js
Module not found: Error: Can't resolve '#rails/activestorage' in '/Users/oli/pre_product/app/javascript/packs'
resolve '#rails/activestorage' in '/Users/oli/xxx/app/javascript/packs'
Parsed request is a module
using description file: /Users/oli/xxx/package.json (relative path: ./app/javascript/packs)
Field 'browser' doesn't contain a valid alias configuration....
Then when I run the app locally(through NGROK), I see Webpacker requesting a file in 'public/packs/js' that doesn't exist. There's other compiled files, but none with the correct name.
It seems like Webpacker is looking in the wrong place for modules, but everything in the webpacker.yml file seems fine.
Any help would be greatly appreciated!
Oli
package.json:
{
"name": "XXX",
"private": true,
"dependencies": {
"#babel/preset-react": "^7.6.3",
"#rails/webpackerj": "^6.0.0-pre.1",
"#shopify/app-bridge": "^1.28.0",
"#shopify/app-bridge-utils": "^1.28.0",
"#shopify/polaris": "^5.12.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"chartjs-plugin-annotation": "^0.5.7",
"prop-types": "^15.7.2",
"rails-ujs": "^5.2.4-4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react_ujs": "^2.6.0",
"turbolinks": "^5.2.0",
"typescript": "^4.1.3",
"webpack-cli": "^4.3.0"
},
"devDependencies": {
"non-digest-webpack-plugin": "0.0.1",
"webpack-dev-server": "^3.11.1"
}
}
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
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
additional_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:
- .mjs
- .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
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
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.8'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.0'
# Use sqlite3 as the database for Active Record
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 6.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 'mini_racer', platforms: :ruby
group :production do
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
end
# Use CoffeeScript for .coffee assets and views
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.7'
gem 'sprockets', '~> 3.0'
gem "clearance"
gem 'spec', '~> 5.3', '>= 5.3.4'
gem 'rspec'
gem 'webpacker'
gem 'jquery-rails'
gem 'chart-js-rails', '~> 0.1.6'
gem 'image_processing', '~> 1.2'
gem 'chartjs-ror'
gem 'inline_svg'
gem 'mailgun-ruby', '~>1.1.6'
gem 'liquid'
# Use Redis adapter to run Action Cable in production
#gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
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]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
gem 'sqlite3'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# 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'
end
gem "non-stupid-digest-assets"
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'rake'
gem 'shopify_app', '~> 15.0'
gem 'shopify_api', '~> 9.0'
gem 'httparty'
#for CORS, i.e. external domain requests via the api controller
gem 'rack-cors'
gem 'whenever', require: false
app/javascript/packs/application.js:
/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
console.log('Hello World from Webpacker')
require("#rails/ujs").start()
require("turbolinks").start()
require("#rails/activestorage").start()
require("channels")
require("jquery");
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
require("shopify_app")
run yarn add #rails/activestorage
It resolves this error

How to fix "Sprockets::FileNotFound: couldn't find file 'turbolinks' with type 'application/javascript'"

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 .

Specified sqlite3 for database adapter but gem is not loaded

I'm new to Rails and was trying to launch my server. Running the command rails server generated an error
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
I looked at many of these previous questions and none seems to solve it. Here is my Gemfile code
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
source 'https://rubygems.org'
gem 'rails', '~> 4.2.0'
gem 'ey_config'
gem 'rails_autolink'
gem 'simple_form'
# Assets
gem 'jquery-rails'
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
platform :ruby do
gem 'mysql2'
gem 'pg'
gem 'activerecord-postgis-adapter', '3.0.0.beta2'
gem 'sqlite3'
gem 'newrelic_rpm'
gem 'unicorn'
gem 'puma'
gem 'json'
gem 'minitest'
gem 'psych'
gem 'racc'
end
platforms :jruby do
ar_jdbc_version = '~> 1.3'
gem 'activerecord-jdbc-adapter', ar_jdbc_version
gem 'activerecord-jdbcmysql-adapter', ar_jdbc_version
gem 'activerecord-jdbcpostgresql-adapter', ar_jdbc_version
gem 'activerecord-jdbcsqlite3-adapter', ar_jdbc_version
gem 'jdbc-mysql', :require => false
gem 'jdbc-sqlite3', :require => false
gem 'jdbc-postgres', :require => false
gem 'jruby-openssl'
gem 'trinidad'
end
platform :rbx do
gem 'rubysl'
gem 'rubysl-test-unit', :require => false
end
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
gem 'tzinfo-data'
end
And here is my database.yml file
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000`
Here is the code in my rakefile:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
Listr::Application.load_tasks
task :travis => ['db:create:all', 'db:migrate', :default]
It will be also appreciated for providing any explanation accompanying the answer. Thanks.
Your sqlite3 gem is not being loaded in production, because of the version mismatch. so, update you gemfile as gem 'sqlite3', '~> 1.3.13' it'll work. Keep it under group :production, :test It'll be good when you push your code to heroku.
Your sqlite3 gem is not being loaded, because of where you've got it in the Gemfile. Take it out of platform :ruby do and place it outside of that block , May be right under gem 'rails', '~> 4.2.0'

Resources