-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Requiring MDC-Web (material-components-web) fails #321
Comments
@michel-zimmer It seems like a bug with the module you are using - Btw have you followed this guide? - https://github.com/material-components/material-components-web#installing-individual-components |
@gauravtiwari Thank you, but unfortunately it is not a bug in the module. The file ( And I've followed the guide: The simplest way is to require the entire To me it looks like the include paths in webpacker are not complete. Maybe |
scss
file coming from a *Node.js* module fails.
scss
file coming from a *Node.js* module fails.
@gauravtiwari I've updated the issue. It uses a more precise example now and shows (as far as I can tell) that the problem comes from webpacker. |
@michel-zimmer Could you please change this in webpack/shared.js to this? resolve: {
extensions: paths.extensions,
modules: [
resolve(paths.source),
'node_modules' // this was absolute before
]
}, |
@gauravtiwari Unfortunately it has the same result. |
Using MCVE: rails _5.1.0_ new webpacker-mdc-mcve --webpack --skip-git --skip-keeps --skip-action-mailer --skip-active-record --skip-action-cable --skip-sprockets --skip-spring --skip-listen --skip-coffee --skip-turbolinks
cd webpacker-mdc-mcve
yarn add @material/animation
echo "import './material.scss'" > app/javascript/packs/material.js
echo '@import "node_modules/@material/animation/mdc-animation.scss"' > app/javascript/packs/material.scss
bin/webpack |
Ohh I see, you would need to do this if you are importing within your sass files - // ~ to tell webpack that this is not a relative import:
@import '~@material/animation/mdc-animation.scss' |
Ah, I see. Then it is the expected behaviour and not a bug in webpacker (or webpack itself). Heading over to MDC-Web people for a solution. |
In the future, a solution could possibly be somewhere in here: material-components/material-components-web#351 For now my solution with a lot of warnings is the following: diff --git a/config/webpack/loaders/sass.js b/config/webpack/loaders/sass.js
index faba9d5..33dd3a5 100644
--- a/config/webpack/loaders/sass.js
+++ b/config/webpack/loaders/sass.js
@@ -1,9 +1,15 @@
const ExtractTextPlugin = require('extract-text-webpack-plugin')
+const { paths } = require('../configuration.js')
module.exports = {
test: /\.(scss|sass|css)$/i,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
- use: ['css-loader', 'postcss-loader', 'sass-loader']
+ use: ['css-loader', 'postcss-loader', {
+ loader: 'sass-loader',
+ options: {
+ includePaths: [paths.node_modules]
+ }
+ }]
})
} |
Document this in README/Guide - #372 |
Just in case, somebody looks here for a solution. With Webpacker 3 a similar fix might look like this: diff --git a/config/webpack/environment.js b/config/webpack/environment.js
index d16d9af..a5c26e4 100644
--- a/config/webpack/environment.js
+++ b/config/webpack/environment.js
@@ -1,3 +1,12 @@
const { environment } = require('@rails/webpacker')
+const merge = require('webpack-merge')
+
+const sassLoaderOptions = {
+ includePaths: environment.toWebpackConfig().resolveLoader.modules
+}
+
+const CSSLoader = environment.loaders.get('style').use.find(el => el.loader === 'sass-loader')
+
+CSSLoader.options = merge(CSSLoader.options, sassLoaderOptions)
module.exports = environment For more details see here: https://github.com/rails/webpacker/blob/master/docs/webpack.md#overriding-loader-options-in-webpack-3-for-css-modules-etc |
Requiring a
scss
file coming from a Node.js module fails.MCVE (updated version to show, that the problem lies in webpacker):
Error message:
But the file (
node_modules/@material/animation/mdc-animation.scss
) exists.Using a fully qualified relative path works:
My expected behaviour is, that both cases do not fail. How do other people think about this? If it's not just me, than I would label this as a bug.
Following is the old example. It is still relevant, becaus it shows, how dependencies are specified in major packages (in the exact same way). Another indicator, that webpacker should be able to handle this case.
Resulting files: webpacker-mdc-mcve.zip
Error message (Full error message: webpack.log.txt):
The text was updated successfully, but these errors were encountered: