-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LESS] CSS Modules cannot be imported from within node_modules. #77458
Comments
Based on the error and environment details you've shared, I'll provide a few potential solutions to fix the Less module import issue in your Next.js project:
npm install --save-dev less less-loader
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config, { isServer }) => {
config.module.rules.push({
test: /\.less$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
mode: 'local',
localIdentName: '[local]_[hash:base64:5]'
}
}
},
'less-loader'
]
});
return config;
}
};
module.exports = nextConfig;
.class {
background-color: #f0f0f0;
padding: 10px;
color: #333;
}
'use client'
import React from 'react';
import styles from './TestStyles.module.less'
const TestComponent = () => {
return (
<div className={styles.class}>
Test Content
</div>
);
};
export default TestComponent; Additional Troubleshooting Steps:
If these solutions don't work, please provide:
Would you like me to elaborate on any of these solutions? |
Thank you for response! I tried your solution, however it did not solve the issue. I tried other approaches also by specifically writing rules for "*.module.less" files, but it did not help also. |
I managed to solve the problem by adding "next-plugin-antd-less" in next.config.ts!
Do not forget to declare module: |
Link to the code that reproduces this issue
https://github.com/Demidog03/next-less-module-issue
To Reproduce
// TestComponent.tsx
Error in local server:
Current vs. Expected behavior
Current behavior:
Expected behavior:
Less module files works fine)
Provide environment information
Operating System: Platform: win32 Arch: x64 Version: Windows 11 Pro Available memory (MB): 31832 Available CPU cores: 12 Binaries: Node: 22.14.0 npm: 10.9.2 Yarn: N/A pnpm: 10.6.3 Relevant Packages: next: 15.2.2 // There is a newer version (15.2.3) available, upgrade recommended! eslint-config-next: 15.2.2 react: 19.0.0 react-dom: 19.0.0 typescript: 5.8.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Webpack
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: