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

rails 6 with webpacker error~ #554

Open
syutran opened this issue Dec 17, 2019 · 14 comments
Open

rails 6 with webpacker error~ #554

syutran opened this issue Dec 17, 2019 · 14 comments

Comments

@syutran
Copy link

syutran commented Dec 17, 2019

ERROR in ./app/javascript/stylesheets/application.scss (./node_modules/css-loader/dist/cjs.js??ref--7-1!./node_modules/postcss-loader/src??ref--7-2!./node_modules/sass-loader/dist/cjs.js??ref--7-3!./app/javascript/stylesheets/application.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):

@import 'rails_bootstrap_forms';
^
File to import not found or unreadable: rails_bootstrap_forms.
in /home/wotogo/myapp/datamart/app/javascript/stylesheets/application.scss (line 2, column 1)
Error:
@import 'rails_bootstrap_forms';
^
File to import not found or unreadable: rails_bootstrap_forms.
in /home/wotogo/myapp/datamart/app/javascript/stylesheets/application.scss (line 2, column 1)
at options.error (/home/wotogo/myapp/datamart/node_modules/node-sass/lib/index.js:291:26)

@lcreid
Copy link
Contributor

lcreid commented Dec 18, 2019

Thanks for taking the time to report this issue. I'm sorry you're having problems.

I'm afraid we haven't had a chance to test and adapt this gem to the Webpacker way of managing assets. We'd be happy to consider a pull request that works for users using the traditional Sprockets asset pipeline, and the Webpacker assets pipeline.

@dtgay
Copy link

dtgay commented Dec 18, 2019

+1 for getting this to work with webpacker.

@addisonmartin
Copy link

I'd also love for this feature to be added! Thanks

@addisonmartin
Copy link

addisonmartin commented Jan 18, 2020

Until this feature can be implemented, I've managed to get this gem to work with Rails 6 and Webpacker:

  1. In config/webpacker.yml, under default, set the extract_css option from false to true.
  2. Create the file app/javascript/packs/stylesheets.scss
  3. Add the @import 'rails_bootstrap_forms'; line within this newly created stylesheets file.

I don't believe this messed up the rest of the application's CSS, but I haven't had the chance to fully test it yet.

Edit: Fixed typo in step one.

@ThomasConnolly
Copy link

addisonmartin: I believe you mean "extract_css," not "extra_css." However, I still get the error: SassError: File to import not found or unreadable: rails_bootstrap_forms.
08:55:17 webpacker.1 | on line 3 of /home/tom/paul/app/javascript/src/application.scss
08:55:17 webpacker.1 | >> @import "rails_bootstrap_forms";

@justinschier
Copy link

@addisonmartin 's trick worked for me. Yes @ThomasConnolly the option is extract_css, not extra_css.

@ThomasConnolly
Copy link

Here is what finally worked for me: I cleared the buildpacks after learning they were not in the correct order. Here are docs from Heroku:

Verify that your buildpacks are set correctly and that Node comes before Ruby:

$ heroku buildpacks
=== myapp Buildpack URLs

  1. heroku/nodejs
  2. heroku/ruby$ heroku buildpacks:add heroku/ruby
    Verify that your buildpacks are set correctly and that Node comes before Ruby:

$ heroku buildpacks
=== myapp Buildpack URLs

  1. heroku/nodejs
  2. heroku/ruby

I also stopped precompiling my assets and let Heroku do that.
Now my app on heroku looks and acts exactly like my local app.

@MtnBiker
Copy link

MtnBiker commented Mar 3, 2020

@addisonmartin Are you still adding the gem?

Implied yes, and I don't see anything in the node_modules that suggest it's installed otherwise.

@addisonmartin
Copy link

@addisonmartin Are you still adding the gem?

Implied yes, and I don't see anything in the node_modules that suggest it's installed otherwise.

What do you mean @MtnBiker? I did not open this issue, only posted a resolution to get the gem working with Rails 6.

To answer your question, I am still using the gem, and there is nothing to install that would appear in node_modules (I think).

@MtnBiker
Copy link

MtnBiker commented Mar 5, 2020

@addisonmartin. Thanks. The node_modules was a (rather obtuse) reference to what bootstrap has installed using Yarn and I had just looked to se if anything that looked like it related to forms.

@niedfelj
Copy link

niedfelj commented Jun 1, 2020

The css is only a few lines, you can also just manually place in your webpacker scss/css also

.rails-bootstrap-forms-date-select select,
.rails-bootstrap-forms-time-select select,
.rails-bootstrap-forms-datetime-select select {
  display: inline-block;
  width: auto;
}

.rails-bootstrap-forms-error-summary {
  margin-top: 10px;
}

romkey added a commit to romkey/lending that referenced this issue Jun 17, 2020
@fritzek
Copy link

fritzek commented Feb 26, 2021

I came across the same issues plus the problem of bootstrap dropdown no longer working. Taking the workaround was showing the same error message. I then added the scss/css manually to app/javascript/stylesheets/application.scss. And now it was working and the dropdown works too.
Here the content of app/javascript/stylesheets/application.scss:

@import "~bootstrap/scss/bootstrap";
// @import "rails_bootstrap_forms";

.rails-bootstrap-forms-date-select select,
.rails-bootstrap-forms-time-select select,
.rails-bootstrap-forms-datetime-select select {
  display: inline-block;
  width: auto;
}

.rails-bootstrap-forms-error-summary {
  margin-top: 10px;
}

@viktorianer
Copy link

Until this feature can be implemented, I've managed to get this gem to work with Rails 6 and Webpacker:

  1. In config/webpacker.yml, under default, set the extract_css option from false to true.
  2. Create the file app/javascript/packs/stylesheets.scss
  3. Add the @import 'rails_bootstrap_forms'; line within this newly created stylesheets file.

I don't believe this messed up the rest of the application's CSS, but I haven't had the chance to fully test it yet.

Edit: Fixed typo in step one.

Unfortunately, it does not work:

ERROR in ./app/javascript/packs/application.scss (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/src??ref--6-2!./node_modules/sass-loader/dist/cjs.js??ref--6-3!./app/javascript/packs/application.scss)
    Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
    SassError: Can't find stylesheet to import.
      ╷
    1 │ @import 'rails_bootstrap_forms';
      │         ^^^^^^^^^^^^^^^^^^^^^^^
      ╵
      app/javascript/packs/application.scss 1:9  root stylesheet
    SassError: SassError: Can't find stylesheet to import.
      ╷
    1 │ @import 'rails_bootstrap_forms';
      │         ^^^^^^^^^^^^^^^^^^^^^^^
      ╵
      app/javascript/packs/application.scss 1:9  root stylesheet

I don't have a solution, but I understand that Webpacker cannot find this file. Because the file is out off scope of Webpacker.

@medir
Copy link

medir commented Aug 5, 2022

I'm not sure if it can be related to this problem but I had a similar error using rails 7 and esbuild and I fixed it by doing the following import adding file extension ".css" into the file "project/app/assets/stylesheets/application.scss":

@import "rails_bootstrap_forms.css";

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

No branches or pull requests