MacOS Django Less Issue

20 views Asked by At

I used Django to use Less on my Windows computer without any issues, but when I switched to MacOS, the system reported an error

enter image description here

StaticCompilationError at /friendLink
node:fs:1336
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, mkdir '/static/styles/less/global'
    at Object.mkdirSync (node:fs:1336:3)
    at module.exports.sync (/Users/taro/.nvm/versions/node/v16.14.0/lib/node_modules/less/node_modules/make-dir/index.js:97:6)
    at ensureDirectory (/Users/taro/.nvm/versions/node/v16.14.0/lib/node_modules/less/bin/lessc:172:7)
    at writeOutput (/Users/taro/.nvm/versions/node/v16.14.0/lib/node_modules/less/bin/lessc:230:7)
    at /Users/taro/.nvm/versions/node/v16.14.0/lib/node_modules/less/bin/lessc:311:9 {
  errno: -2,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: '/static/styles/less/global'
}

Step:

pip install django-static-precompiler
npm install less -g

Django setting.py:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/static/')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

STATIC_PRECOMPILER_OUTPUT_DIR = ''

Django templates:

{% load compile_static %}
{% load static %}
...
<link rel="stylesheet" href="{% static "styles/less/global/components.less"|compile %}"/>

I am certain that the Django project has this folder/static/styles/less/global

enter image description here

  1. I thought it was a permission issue
$ where lessc
/Users/taro/.nvm/versions/node/v16.14.0/bin/lessc

sudo chmod +x /Users/taro/.nvm/versions/node/v16.14.0/bin/lessc

But it's useless

  1. I also tried PyCharm's File Watcher settings But it shouldn't be a problem. When I write a less file and save it, CSS will still appear

Is it a problem with NVM, django static precompiler configuration, or macos? I'm not sure

0

There are 0 answers