scss @import fail
See original GitHub issueHi, I am using css-modules-require-hook on my koa.js server. I do server side rendering of react components. It worked fine when just using css but now we want to switch to Sass in order to use variables.
I am using the following code to compile scss on runtime:
// css modules
const cssRequireHook = require('css-modules-require-hook');
const sass = require('node-sass');
cssRequireHook({
generateScopedName: '[name]__[local]___[hash:base64:5]',
extensions: [ '.scss', '.css' ],
preprocessCss: data => sass.renderSync({ data }).css
});
It works, but as soon as I try to @import
any other .scss file it breaks
@import '../../styles/variables';
.myclass {
background: $color-white;
clear: both;
}
in variables.scss
$color-white: #000;
the error I get:
/Users/tmaximini/data/frontend-node/node_modules/node-sass/lib/index.js:424
throw util._extend(new Error(), JSON.parse(result.error));
^
Error: File to import not found or unreadable: ../../styles/variables
the path is definitely correct, and webpack handles it fine on client. I don’t use webpack on my server code so I hoped that the require-hook can somehow resolve these @imports.
Any idea how to achieve this? thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Webpack throwing error on SCSS @import SCSS
I managed to reproduce the error and it seems to come from: include: [ path.resolve(__dirname, 'styles') ],. The path is the issue cause...
Read more >SCSS imports fail · Issue #6058 - GitHub
I had a working webpack setup for my project. But out of a sudden, the loader can't import any of the following modules:...
Read more >Sass: @import
When Sass imports a file, that file is evaluated as though its contents appeared directly in place of the @import . Any mixins,...
Read more >Error on importing scss files. | React - EJ 2 Forums - Syncfusion
import the scss files from the node modules package in your App. · install the node-sass package using the command “npm install node-sass...
Read more >scss @import fail - Laracasts
I'm a newbie here so please let me know if I've overlooked something obvious. I'm trying to employ the general practice of keeping...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Presumably sass resolves paths from the working directory. I’d like to suggest you to try this:
from: https://github.com/sass/node-sass#file
seems to work when I tell the
sass.renderSync
function to include my styles path: