Not sure if it is an actual bug or my curly hands, but i tried to provide as more details as possible to help solve this problem.
Yes
Yes
node -v
: 6.9.5npm -v
:4.6.1npm ls react-scripts
(if you haven鈥檛 ejected): [email protected]Then, specify:
(Write your steps here:)
@import "~react-select\scss\default.scss
&& npm start
{
"status": 1,
"file": "{my local path here}/test/src/App.scss",
"line": 1,
"column": 1,
"message": "File to import not found or unreadable: ~react-select/scss/default.\nParent style sheet: {my local path here}//test/src/App.scss",
"formatted": "Error: File to import not found or unreadable: ~react-select/scss/default.\n Parent style sheet: {my local path here}/test/src/App.scss\n on line 1 of src/App.scss\n>> @import \"~react-select/scss/default\";\
n ^\n"
}
Just normal scss compile, coz it OK works for files not from node modules. BTW importing css works fine from node_modules
{
"status": 1,
"file": "{my local path here}/test/src/App.scss",
"line": 1,
"column": 1,
"message": "File to import not found or unreadable: ~react-select/scss/default.\nParent style sheet: {my local path here}//test/src/App.scss",
"formatted": "Error: File to import not found or unreadable: ~react-select/scss/default.\n Parent style sheet: {my local path here}/test/src/App.scss\n on line 1 of src/App.scss\n>> @import \"~react-select/scss/default\";\
n ^\n"
}
Is it a bug though? The ~
notation is webpack-specific. If I understand correctly, when Sass is precompiled by its own CLI, it processes @import
s by itself, and thus doesn鈥檛 understand ~
notation. I think if you replaced this with node_modules/
instead it might work.
@gaearon Thank you a lot! this is definitely a bug, but in my head!
Thanks @gaearon!
For people coming from google and for future reference, I had to change @import "sass-mq/mq"
to @import "node_modules/sass-mq/mq"
to fix the import of sass-mq.
in your webpack.config.js
file, add
{
module:{
rules: [
{ test : /\.scss$/,
uese: {
loader: 'sass-loader',
options: {
includePaths: [
path.resolve('../node_modules'), // @import('jeet/scss/jeet/index')
...
]
}
}
so that you don't have to put node_modules
in your code
This worked for me locally, but when deploying through Jenkins I had the same problem again. This fixed it though:
// src/index.scss
@import 'variables';
@import '../node_modules/picnic/src/themes/default/colors';
@import '../node_modules/picnic/src/themes/default/theme';
@import '../node_modules/picnic/src/plugins/normalize/plugin';
@import '../node_modules/picnic/src/plugins/grid/plugin';
// ...
Adding the ../
in the beginning, since it is a relative path and node_modules
are not inside src
. I have no idea why it works without the ../
in local dev though.
Worth noting that this node_modules
prefix trick also works with Next.js.
I have this issue but its with my variables.scss from the root of my project rather than node modules
I have this issue but its with my variables.scss from the root of my project rather than node modules
How did you resolve it??
@The-Code-Monkey did you resolve it?
Most helpful comment
Is it a bug though? The
~
notation is webpack-specific. If I understand correctly, when Sass is precompiled by its own CLI, it processes@import
s by itself, and thus doesn鈥檛 understand~
notation. I think if you replaced this withnode_modules/
instead it might work.