Recently, I utilized Create React App (CRA) to create a new project and then included node-sass
in order to import SCSS files.
An example:
import "./App.scss";
Although this method works without any issues, I encountered a problem when trying to load styles asynchronously using import()
. In a previous JavaScript project, I successfully used this technique. However, after converting it to TypeScript, I started receiving the following compiler error:
Cannot find module './fallback.scss' or its corresponding type declarations. TS2307
Below is a Minimal Viable Example showcasing the problematic code:
async function loadFallbackStyles(): Promise<void> {
if (window.navigator.userAgent.includes("Trident/")) {
await import("./fallback.scss");
}
}
I attempted to resolve this issue by adding
declare module "*.scss"
to my type declarations, but unfortunately, that did not solve the problem.