question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

node_modules resolve not working with @import for SCSS

See original GitHub issue

I’m running into this error msg when I’m trying to @import a .scss file from my node_modules folder via this method:

@import "react-input-range/src/scss/index.scss";

Results in this error:

[!] (postcss plugin) Error: File to import not found or unreadable: react-input-range/src/scss/index.scss.

However, if I include the entire relative path to the .scss, that’ll work:

@import "../../../../../../node_modules/react-input-range/src/scss/index.scss";

and this works as well

@import "react-input-range/lib/css/index.css";

I need to import the .scss to override the SASS variables, so can’t make use of of the .css file. I can’t seem to figure out the cause and need some assistance with my issue, thanks!


So to reiterate:

Component.scss

// Works
@import "react-input-range/lib/css/index.css"; 
@import "../../../../../../node_modules/react-input-range/src/scss/index.scss";

// Does not work
@import "react-input-range/src/scss/index.scss";

rollup.config.js

import easyImport from "postcss-easy-import";
import postcssFlexbugsFixes from 'postcss-flexbugs-fixes';
import autoprefixer from "autoprefixer";

postcss({
    sourceMap: true,
    minimize: true,
    modules: true,
    namedExports: true,
    plugins: [
        easyImport,
        postcssFlexbugsFixes,
        autoprefixer({
            browsers: [
                '>1%',
                'last 4 versions',
                'Firefox ESR',
                'not ie < 9', // React doesn't support IE8 anyway
            ],
            flexbox: 'no-2009',
        }),
    ],
    extract: path.resolve("./dist/style.css"),
}),

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
egoistcommented, Feb 26, 2018

Does @import "react-input-range/src/scss/index.scss"; work in regular node-sass? From what I can tell it’s importing a file relative to cwd instead of the one in node_modules.

However I think you can use includePaths option to make this work:

postcss({
	use: [
		['sass', {
			includePaths: [path.resolve('node_modules')]
		}]
	]
})
3reactions
egoistcommented, Feb 26, 2018

btw in v1.3.0 you can prepend it with ~ to import from node_modules, see: https://github.com/egoist/rollup-plugin-postcss#imports

Read more comments on GitHub >

github_iconTop Results From Across the Web

node_modules resolve not working with @import for SCSS #345
I'm running into this error msg when I'm trying to @import a .scss file from my node_modules folder via this method: @import "react-input-range/ ......
Read more >
SCSS cannot resolve imports (node_modules) in IDE - YouTrack
SCSS cannot resolve imports (node_modules) in IDE - but actually works on ng serve. Relates to 2 Duplicates 1. Relates to 2 issues...
Read more >
Webpack can't resolve @import of scss/css - Stack Overflow
Before I was trying to import another file into my stylesheet, I got my *.css file back. Everything works, the only problem starts,...
Read more >
Import a SCSS files from Node Modules - Laracasts
Hi, I'm trying to load some styles from the node_modules folder. But it's a real pain to do so. Usually, when I'm not...
Read more >
Sass: @import
The @import rule has a number of serious issues: ... users to provide load paths: paths on the filesystem that Sass will look...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found