create-react-app 2.0, how to use absolute path import in sass/scss files?
See original GitHub issueIs this a bug report?
No
The problem
I am using creacte-react-app 2.0.0-next.66cc7a90, which already has support for Sass/Scss files
however with default relative import in Sass/Scss files, i have to use code like
@import "../../../../../styles/variables/_variables.scss";
instead I want to use absolute import so i can import with code
@import "styles/variables/_variables.scss";
I know one way to acheve so is to update options
{
loader: "sass-loader",
options: {
includePaths: ["absolute/path/a", "absolute/path/b"]
}
but I want to do it without ejecting, how can i do it? using react-app-rewired?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:22 (4 by maintainers)
Top Results From Across the Web
create-react-app 2.0, how to use absolute path import in sass ...
Assuming styles/abstracts/_variables.scss exists under src , you could do the following: SASS_PATH=src yarn start.
Read more >Adding a Sass Stylesheet - Create React App
To use imports relative to a path you specify, you can add a .env file at the project root with the path specified...
Read more >Absolute imports with Create React App | by David Gilbertson
With the release of Create React App 3, we now have the ability to use absolute import paths, without ejecting. Hallelujah.
Read more >Absolute imports in Create React App - DEV Community
Thanks a lot! Have you any tips in case if I want organize paths for styles structure? What should I do with imports...
Read more >How to use Sass and CSS Modules with create-react-app
Up until the release of create-react-app v2, if you wanted to include Sass or CSS Modules in your project, you would have to...
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
@Timer This is an issue when using SCSS files from NPM packages where they also get SCSS files from other packages.
A very good example is
@material
: You will need to import their SCSS like so:But inside their SCSS file they have:
So the build breaks as they do not have the
~
. On their side, it makes sense as that’s how SASS works. Butsass-loader
makes it complex as they need the~
to go look inside thenode_modules
.For CRA, including this option fixes this problem (tested on my local):
I’m successfully using absolute imports with
~
andNODE_ENV
set in .env/.env:
given that /src/styles/variables.scss exists, in any .scss file:
works fine with in v2.0.