如何解决Odoo 9中无法执行lessc命令的问题
Hey there, let's work through this frustrating 'lessc' not found issue you're hitting with Odoo 9 on Windows. I've troubleshooted similar problems for other users, so here are actionable steps to get things working:
1. Verify System PATH Includes Node.js and Global npm Directories
Windows often fails to recognize global npm commands if their paths aren't in the system environment variables. Here's how to check and fix it:
- Right-click This PC → Properties → Advanced System Settings → Environment Variables.
- In the System Variables section, look for the
Pathvariable. - Ensure it includes:
- Your Node.js installation folder (typically
C:\Program Files\nodejs\) - The global npm packages folder (usually
C:\Users\[YourUsername]\AppData\Roaming\npm)
- Your Node.js installation folder (typically
- If either path is missing, click Edit and add them. Then restart your command prompt (or even your PC) to apply changes.
2. Reinstall Less Globally with Admin Rights
Sometimes the initial global install fails silently due to permission issues. Let's reset it:
- Open Command Prompt as Administrator (right-click Command Prompt → Run as administrator).
- Uninstall the existing Less package:
npm uninstall -g less - Reinstall a version compatible with Odoo 9 (newer versions might cause conflicts):
npm install -g less@2.7.3 - Test if
lesscworks by running:
You should see the version number printed if the install was successful.lessc -v
3. Specify the Full Path to lessc in Odoo's Configuration
Odoo might not locate lessc automatically on Windows. Update your Odoo config file (usually odoo.conf) to point directly to the lessc.cmd file:
- Open
odoo.confin a text editor. - Look for the
lesscline (add it if it doesn't exist) and set it to:
Replacelessc = "C:\Users\[YourUsername]\AppData\Roaming\npm\lessc.cmd"[YourUsername]with your actual Windows username.
4. Restart Odoo and Clear Browser Cache
Changes to environment variables or config files won't take effect until you restart services:
- Close the Odoo server window completely, then restart it.
- In your browser, clear the cache (press
Ctrl+Shift+Del, select "Cached images and files", then click "Clear data"). - Refresh the Odoo page and check if the error is gone.
5. Check Node.js Version Compatibility
Odoo 9 is an older version, so it might not play well with the latest Node.js releases. If the above steps don't work, try downgrading Node.js to a compatible version like 12.x or 14.x (LTS versions are safest). You can use nvm-windows to switch between Node.js versions easily without uninstalling anything.
内容的提问来源于stack exchange,提问作者Dhouha

