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.

Cannot import scss/sass

See original GitHub issue

Prerequisites

Expected Behavior

While importing [.scss/.sass] files, the application (yarn dev) should build with no errors.

Current Behavior

When I import [.scss/.sass] files (ex changing Home.css to Home.scss), the application (yarn dev) gives me this error:

ERROR in ./app/components/Home.scss
Module build failed (from ./node_modules/typings-for-css-modules-loader/lib/index.js):
Error: Cannot find module 'css-loader/locals'

Steps to Reproduce

  1. Change the file ./app/components/Home.css to ./app/components/Home.scss (or .sass)

  2. Change the file ./app/components/Home.tsx to reflect the change mentioned above.

  3. Run yarn dev

Possible Solution (Not obligatory)

Probably Webpack is not properly configured to process scss/sass, even though it has rules to deal with those file extensions.

Context

I’m trying to use scss/sass files, as it is common in React, and this error is happening.

Your Environment

  • Node version : v12.18.1
  • electron-react-boilerplate version or branch : master
  • Operating System and version : Windows 10

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
amilajackcommented, Sep 26, 2020

This might have been fixed in the most recent version of ERB, released yesterday. Please check if those changes work for you

1reaction
megancoopercommented, Mar 2, 2021

@amilajack Is this still an ongoing problem? I have the latest version of ERB (v2.1.0) and am still encountering an issue where I can’t import *.scss files from a *.tsx file.

Cannot find module './style.scss' or its corresponding type declarations.ts(2307)
Screen Shot 2021-03-01 at 12 55 11 AM

Update:

I was able to remove this typescript error by adding a declaration.d.ts file in the root project directory with the following contents:

StackOverflow Issue

// We need to tell TypeScript that when we write "import styles from './styles.scss' we mean to load a module (to look for a './styles.scss.d.ts').
declare module '*.scss';

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't import CSS/SCSS modules. TypeScript says "Cannot ...
In a webpack configuration that pipes *.scss files through sass-loader → css-loader → style-loader, there will be no content in the imported module, ......
Read more >
Sass: @import
Sass extends CSS's @import rule with the ability to import Sass and CSS stylesheets, providing access to mixins, functions, and variables and combining ......
Read more >
sass-loader - webpack - JS.ORG
Loads a Sass/SCSS file and compiles it to CSS. ... If it cannot be resolved, then the loader will try to resolve @import...
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 >
Cannot Find Module 'XXX.scss' or Its Corresponding Type ...
First of all, make sure that webpack and sass have been able to recognize the CSS Module, please refer to the webpack official...
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