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.

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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
rmanguinhocommented, May 12, 2020

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’ }

1reaction
rmanguinhocommented, May 9, 2020

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’

Read more comments on GitHub >

github_iconTop 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 >

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