TS + SCSS = Cannot find module '../mocks/index.scss'.
See original GitHub issue🐛 Bug Report
It seems to happen on the latest jest + ts-jest.
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
shared/components/Carousel/__tests__/index.test.tsx:6:20 - error TS2307: Cannot find module '../index.scss'.
6 import styles from '../index.scss'
To Reproduce
Steps to reproduce the behavior:
//...
import styles from '../mocks/index.scss' // fails while test is running here
describe('Test', () => {
//...
})
Expected behavior
Should handle .scss imports without crashing.
Link to repl or repo (highly encouraged)
./jest.config.js configuration
module.exports = {
cacheDirectory: '<rootDir>/.tmp/jest',
coverageDirectory: './.tmp/coverage',
moduleNameMapper: {
'^.+\\.(css|scss|cssmodule)$': 'identity-obj-proxy'
},
modulePaths: ['<rootDir>'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
globals: {
NODE_ENV: 'test'
},
verbose: false,
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
testPathIgnorePatterns: ['/node_modules/', '/__tests__/mocks/.*'],
coveragePathIgnorePatterns: ['typings.d.ts'],
transformIgnorePatterns: ['.*(node_modules)(?!.*torn.*).*$'],
transform: {
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest'
},
setupFiles: [
'<rootDir>/setupTests.js'
// '<rootDir>/node_modules/whatwg-fetch/fetch.js' // should be removed in future due to the tests running collision
],
snapshotSerializers: ['enzyme-to-json/serializer']
}
envinfo
System:
OS: macOS 10.15.3
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 12.16.0 - /usr/local/bin/node
Yarn: 1.22.0 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
npmPackages:
jest: ^25.1.0 => 25.1.0
ts-jest: 25.2.1
babel-jest: 25.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Can't import CSS/SCSS modules. TypeScript says "Cannot ...
I'm trying to import a theme from a CSS module but TypeScript gives me a "Cannot Find Module" ...
Read more >Cannot Find Module 'XXX.scss' or Its Corresponding Type ...
When using CSS Module in Typescript + Webpack + Sass projects, you can use CSS modules normally, but vscode always prompts cannot find...
Read more >How to fix TypeScript cannot find module CSS/SCSS in Next.js
To solve “cannot find module CSS/SCSS” in your Next.js project, you must declare a new module in your next-env.d.ts file.
Read more >Cannot find .scss module error – Enabling SASS integration ...
When creating SharePoint framework webparts in Visual Studio code, out of the box integration with SASS files (.scss) does not work. You get...
Read more >Typescript cannot find scss module : WEB-56335
ts file is placed in the root directory of the repository and included in tsconfig file.) But, Sometimes I still get a error...
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

Actually you need to remove node_modules and package.lock, than run npm install. The config is just this line in jest.config: moduleNameMapper: { ‘\.scss$’: ‘identity-obj-proxy’ }
Do you have a GitHub repo with an example? I’m trying to make this work for days. If I test a file that loads SCSS file my test always fails and says: cannot find module ‘xxx.scss’