Rails 6.0.3.4 [Webpacker] Compilation failed - ruby-on-rails

After upgrade to 6.0.3 webpack cannot read property 'plugins' in the environment.js during assets:precompile
[Webpacker] Compiling...
[Webpacker] Compilation failed:
[webpack-cli] Failed to load '/planned_maintenance/config/webpack/development.js'
[webpack-cli] TypeError: Cannot read property 'plugins' of undefined
at Object.<anonymous> (/planned_maintenance/config/webpack/environment.js:4:13)
at Module._compile (/planned_maintenance/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (/planned_maintenance/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/planned_maintenance/config/webpack/development.js:4:21)
at Module._compile (/planned_maintenance/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
Completed 500 Internal Server Error in 3397ms (ActiveRecord: 0.0ms | Allocations: 14850)
ActionView::Template::Error (Webpacker can't find application in /planned_maintenance/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
):
7:
8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9: <%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
10: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
11:
12: </head>
13:
app/views/layouts/application.html.erb:10
config/webpack/environment.js looks like this:
const { environment } = require('#rails/webpacker')
const webpack = require("webpack")
environment.plugins.append("Provide", new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
}))
module.exports = environment
development.js
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()
I've fixed the failure to load issue. It came down to package.json listing a wrong version number.
The issue now is on the rails console:
[Webpacker] Compiling...
[Webpacker] Compiled all packs in /Users/Lorenzo/code/LorenzoXavier/planned_maintenance/public/packs
Completed 500 Internal Server Error in 2221ms (ActiveRecord: 0.0ms | Allocations: 18151)
ActionView::Template::Error (Webpacker can't find application in /Users/Lorenzo/code/LorenzoXavier/planned_maintenance/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
):
7:
8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9: <%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
10: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
11:
12: </head>
13:
app/views/layouts/application.html.erb:10
So I've tried:
stopping rails server
Running rails assets:clobber
Then running bin/webpack-dev-server
That has fed back an error:
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- /Users/Lorenzo/code/LorenzoXavier/planned_maintenance/node_modules/webpack-dev-server/bin/webpack-dev-server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/Lorenzo/code/LorenzoXavier/planned_maintenance/node_modules/webpack-dev-server/bin/webpack-dev-server.js:65:1)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/Lorenzo/code/LorenzoXavier/planned_maintenance/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
]
}

Environments is nil because you haven't imported webpacker.
Try including this above your const webpack line
const { environment } = require('#rails/webpacker');

Related

Ruby - Webpacker can't find application in

After installing the device gem, I encountered an error. How can i fix this:
Webpacker can't find application in /home/grkmdgn06/Desktop/my5_homework/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
Extracted source (around line #9):
...
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> # error line
...
perhaps your node.js is out of date
try this:
sudo npm install n -g
sudo n stable
bundle exec rake webpacker:install

Unable to deploy TailwindCSS on a Rails 6 app to Heroku

I'm currently trying to deploy my rails 6 application to Heroku. I tried the answer in a post about a similar issue but had no luck.. I'm not sure where the error is coming from since the styles work well on development but break when pushing to production. Not sure if it has to do with the fact that it is currently compiling css assets with sass?
[14] ./node_modules/#rails/actiontext/app/javascript/actiontext/index.js + 1 modules 2.64 KiB {0} [built]
remote: | 2 modules
remote: + 7 hidden modules
remote:
remote: ERROR in ./app/javascript/stylesheets/application.scss
remote: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
remote: ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
remote:
remote: #import "tailwindcss/base";
remote: ^
remote: File to import not found or unreadable: tailwindcss/base.
remote: in /tmp/build_d98149372aae5001d8aada1182784254/app/javascript/stylesheets/application.scss (line 1, column 1)
remote: at runLoaders (/tmp/build_d98149372aae5001d8aada1182784254/node_modules/webpack/lib/NormalModule.js:316:20)
Not sure why is File to import not found or unreadable: tailwindcss/base. not loading. From the documentation on Tailwind it shows to add it via #import
javascript/stylesheets/application.scss
​
#import "tailwindcss/base";
#import "tailwindcss/components";
#import "tailwindcss/utilities";
Tailwind is also showing in the dependencies.
package.json
"version": "0.1.0",
"devDependencies": {
"tailwindcss": "^1.2.0",
"webpack-dev-server": "^3.7.1"
}
views/layouts/application.html.erb
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
if no asset processor is defined it defaults to sass which is what I'm using to compile the css. I thought this could be a reason why is not working.
config/environments/production.rb
# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass
config.assets.js_compressor = :uglifier
postcss.config.js
module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
require('postcss-import'),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
})
]
}
From reading the related Stack overflow post set extract_css: to true
webpacker.yml
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
What could the problem be?
"devDependencies": {
"tailwindcss": "^1.2.0",
"webpack-dev-server": "^3.7.1"
}
Tailwind is within dev dependencies so this won't work in production move the dependence outside of devDependencies so it can be used in production.

First rails application: routes.rb not leading to right page(?)

Apologies in advance if this is so basic I probbaly shouldn't post it here. I'm not even sure if the title actually describes the issue. I am just starting to look at Ruby on Rails, and am following this page to set up "my first application": http://guides.rubyonrails.org/getting_started.html
Now, when I get to the point where I add
root 'welcome#index'
Into the routes.rb file and try and access it, it all goes wrong. First I thought it was a permissions issue, but I can access the views/layouts/welcome/index.html.erb file directly in the browser.
I'm so new to this that I haven't got far enough to know what I'm looking for in troubleshooting, hence this post.
When starting the rails server, I do get what looks like errors on restart and hangup signals, but I doubt this is the problem. Output listed here just in case.
=> Booting Puma
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.3-p222), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Loading the root page gives the following server output:
Started GET "/" for 127.0.0.1 at 2017-06-28 13:17:23 +0200
Processing by WelcomeController#index as HTML
Rendering welcome/index.html.erb within layouts/application
Rendered welcome/index.html.erb within layouts/application (13.0ms)
Completed 500 Internal Server Error in 3742ms
ActionView::Template::Error (TypeError: Object doesn't support this property or method):
5:
6: <%= csrf_meta_tags %>
7:
8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
10:
11: </head>
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb___750167210_57076860'
It kind of looks to me as though it does load the index page, but then something else triggers and it's redirected to a page that doesn't work. The content of the page it's directed to (views/layouts/application.html.erb) is:
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
Content of routes.rb for reference is:
Rails.application.routes.draw do
get 'welcome/index'
root 'welcome#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Add below lines in /assets/stylesheets/application.css
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/

Deploying a Rails App to VPS, with NginX Server. Compile Issues

I successfully deployed my rails app to my VPS, but when I try to look at my server from browser, I get a 500 error ("We're sorry, but something's wrong"). The app is working fine locally, so I think the problem lies in not my code but somewhere else.
Here's the log from /current/log/production.log
ActionView::Template::Error (jquery.js isn't precompiled):
4: <title>Songhomme</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= javascript_include_tag 'jquery' %>
8: <%= csrf_meta_tags %>
9: </head>
10: <body>
app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___2525571063257357898_28769560'
I also got the following error:
ActionView::Template::Error (/home/deployer/apps/songhomme/releases/20121204091428/app/views/posts/_posts.erb:27: syntax error, unexpected ',', expecting ')'
...ppend= ( link_to (t.name + " ", '/tags/' + t.id.to_s) );#out...
The code is working fine locally, so I'm not sure what's wrong with the second part of code. For the first part of code, does running rake assets:precompile before I push to my repo solve the problem?
I appreciate your help.
Try declaring your js includes in the manifest file application.js , not by javascript_include_tag. Since Rails version 3 this is the proper way . So , in your application.js :
//= require jquery
//= require jquery_ujs

Unexpected Character '#' deploying to Heroku

I'm stuck trying to get my app to work on heroku. I can run locally and it works well, but when I deploy to heroku I get the following error:
2012-05-18T21:26:18+00:00 app[web.1]: (in /app/app/assets/javascripts/application.js.erb)):
2012-05-18T21:26:18+00:00 app[web.1]: 8: <%= render 'layouts/shim'%>
2012-05-18T21:26:18+00:00 app[web.1]: ActionView::Template::Error (Unexpected character '#'
2012-05-18T21:26:18+00:00 app[web.1]: 4: <title><%= full_title(yield(:title))%></title>
2012-05-18T21:26:18+00:00 app[web.1]:
2012-05-18T21:26:18+00:00 app[web.1]: 5: <%= stylesheet_link_tag "application", :media => "all" %>
2012-05-18T21:26:18+00:00 app[web.1]: 7: <%= csrf_meta_tags %>
2012-05-18T21:26:18+00:00 app[web.1]: 3: <head>
2012-05-18T21:26:18+00:00 app[web.1]: 6: <%= javascript_include_tag "application" %>
2012-05-18T21:26:18+00:00 app[web.1]: app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___39687462904242755_48413880'
2012-05-18T21:26:18+00:00 app[web.1]:
2012-05-18T21:26:18+00:00 app[web.1]:
9: </head>
Initially I thought it was a coffeescript problem. But I have since gotten rid of any .coffee files just to see if it will work. Still, the same result
This is my application.js file:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .
$(document).ready(function()
{
function setCountdownTimer(element, year, month, day) {
var date = new Date(year, month, day);
$(element).countdown({until: date});
}
$('#hashtag_id').live('change', function() {
$('#user_comments').empty();
$.ajax({ url: '/headlines/update_comments/',
data: {hashtag: this.value, id: $('#headline_tag').data('id')},
success: function(data) {
$('#user_comments').html(data);
}
})
});
});
Any ideas?
Have you changed any of the coffee script files to just js files, and left the comments at the top in:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
Remove these comments, if so.
This error occurs often in tandem with another asset pipeline error when Devise is installed. Before investigating the solutions stated here
rails 3.1.0 ActionView::Template::Error (application.css isn't precompiled)
try Snowangel's suggestion first to save time.

Resources