react-slick builds, but the slick-carousel CSS import cannot be found
Module not foundShort answer
react-slick does not bring its stylesheets with it. They come from the separate slick-carousel package, so the CSS import fails when that package is not installed. The other causes are a wrong path inside the package, since the files sit in its slick folder, and a file name written with different casing, which breaks on case-sensitive Linux builds.
Fix it fast
1Find out which cause you have
Check that the package is installed and look at the files inside it. Your import path has to match one of them exactly.
npm ls slick-carousel ls node_modules/slick-carousel/slick2Match what you see, then jump to its fix
- 1
npm ls slick-carousel lists nothing, and the failing import names a path under slick-carouselslick-carousel is not installedFix - 2
slick-carousel is installed, yet the build still cannot find the file you importThe import path does not match a file in the packageFix - 3
The import works on your laptop but the same commit fails in a Linux CI jobThe file name differs in casing, so Linux builds fail while another machine passesFix
- 1
What does the error look like?
Module not foundThe build stops on the line import "slick-carousel/slick/slick.css";
Cause 1 of 3
slick-carousel is not installed
1Check
The react-slick README installs the stylesheets with a second package, slick-carousel. A project that ran only npm install react-slick has the component but no CSS files.
ls node_modules/slick-carousel2Fix
Install the package. If you cannot add it, the README also offers two stylesheet links to put in the page head instead.
npm install slick-carousel
<!-- alternative: in the HTML head -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css" />3Verify
The folder now lists slick.css and slick-theme.css, and the build gets past the import.
ls node_modules/slick-carousel/slickConfirmed by raw.githubusercontent.com
Cause 2 of 3
The import path does not match a file in the package
1Check
The stylesheets live in the package's slick folder: slick.css is required and slick-theme.css is optional. A path such as slick-carousel/slick.css, without the slick folder, points at nothing.
grep -rn "slick-carousel" src2Fix
Import the two files with their full paths, once, in a component or entry file that is always loaded.
import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";3Verify
Start the dev server again; the carousel renders with its arrows and dots styled.
npm run devConfirmed by raw.githubusercontent.com
Cause 3 of 3
The file name differs in casing, so Linux builds fail while another machine passes
1Check
Next.js documents that wrong casing in an import breaks on case-sensitive environments such as most Linux-based CI, even if it passes locally.
ls node_modules/slick-carousel/slick
grep -rn "slick-carousel" src2Fix
Write the file names exactly as the folder lists them: slick.css and slick-theme.css, all lower case.
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";3Verify
Run the production build in a Linux environment, such as your CI job, and confirm it passes.
npm run buildConfirmed by nextjs.org
How do I stop it coming back?
- Add slick-carousel to package.json in the same commit that adds react-slick, so a fresh install always has both.
- Run the production build in CI on Linux, so a casing slip is caught before release.
- Import the slick stylesheets in one place only, so there is a single line to check when a carousel loses its styles.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix