External SCSS with JSX and Typescript : cannot find module, jsx doesn't exist
See original GitHub issueExamples bug report
Example app with next-sass
with-external-styled-jsx-sass link
Describe the bug
Lint error when you install sass jsx with typescript
To Reproduce
- Create project
yarn create next-app --example with-external-styled-jsx-sass with-external-styled-jsx-sass-app
- Add dependencies in package.json
{
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"type-check": "tsc"
},
"dependencies": {
"@zeit/next-typescript": "^1.1.1",
"next": "^8.1.0",
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
"devDependencies": {
"node-sass": "^4.7.2",
"sass-loader": "7.1.0",
"@types/next": "^7.0.6",
"@types/react": "^16.4.16",
"@types/react-dom": "16.0.11",
"typescript": "3.2.4"
}
}
-
yarn install
- Add typescript to next config
const withTypescript = require('@zeit/next-typescript')
module.exports = withTypescript({
webpack: (config, { defaultLoaders }) => {
config.module.rules.push({
test: /\.scss$/,
use: [
defaultLoaders.babel,
{
loader: require('styled-jsx/webpack').loader,
options: {
type: 'scoped'
}
},
'sass-loader'
]
})
return config
}
})
- rename index.js to index.tsx
Expected behavior
yarn dev It work but I don’t know why linter say module are not found or jsx doesn’t exist.
Screenshots
If applicable, add screenshots to help explain your problem.

System information
- OS: Windows
- Webstorm and VS Code
- Version of Next.js: ^8.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Can't import CSS/SCSS modules. TypeScript says "Cannot ...
I was using the typescript-plugin-css-modules plugin, was getting the error still on build, and this resolved it for me.
Read more >How to use CSS Modules with TypeScript and webpack
You'll get an error: “Cannot find module './Button.css'”. There are several ways to fix that. The easy way. You can bypass TypeScript import...
Read more >API - ESBuild
This API call is used by the command-line interface if no input files are provided and the --bundle flag is not present. In...
Read more >Features | Vite
TypeScript #. Vite supports importing .ts files out of the box. Vite only performs transpilation on .ts files and does NOT perform ...
Read more >FAQs - styled-components
styled-components v5 does not introduce any breaking public API changes, ... </React.Fragment>. See the documentation for createGlobalStyle to see all the ...
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 Free
Top 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

In case anyone’s seeing this now, sass and css can be added easily using built in module support.
/components/topbar.module.scss/components/topbar.tsxA global style sheet
styles.scsscan be placed at the root of the folder too.styles.scssMay be useful for someone:
Currently, it’s almost impossible to make SCSS and SASS work in newer versions of Next. At least it’s unreasonably hard.
Instead of using scss or sass, I ended up using MaterialUI and its
makeStyleshelper, so styles are stored in a separate file withtsextension.For those who don’t like the idea of using MaterialUI (I don’t like it either, honestly), then styled-jsx is the way. As recommended by official docs.