bootstrap_form icon indicating copy to clipboard operation
bootstrap_form copied to clipboard

rails 6 with webpacker error~

Open syutran opened this issue 5 years ago • 14 comments
trafficstars

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)

syutran avatar Dec 17 '19 12:12 syutran

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.

lcreid avatar Dec 18 '19 03:12 lcreid

+1 for getting this to work with webpacker.

dtgay avatar Dec 18 '19 16:12 dtgay

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

addisonmartin avatar Jan 18 '20 04:01 addisonmartin

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.

addisonmartin avatar Jan 18 '20 05:01 addisonmartin

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";

ThomasConnolly avatar Feb 29 '20 13:02 ThomasConnolly

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

justinschier avatar Mar 01 '20 03:03 justinschier

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.

ThomasConnolly avatar Mar 01 '20 13:03 ThomasConnolly

@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.

MtnBiker avatar Mar 03 '20 19:03 MtnBiker

@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).

addisonmartin avatar Mar 05 '20 02:03 addisonmartin

@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.

MtnBiker avatar Mar 05 '20 02:03 MtnBiker

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;
}

niedfelj avatar Jun 01 '20 17:06 niedfelj

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;
}

fritzek avatar Feb 26 '21 15:02 fritzek

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.

viktorianer avatar Jul 11 '21 13:07 viktorianer

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";

medir avatar Aug 05 '22 13:08 medir