andreyfedoseev / django-static-precompiler

Django Static Precompiler provides template tags and filters to compile CoffeeScript, LiveScript, SASS / SCSS, LESS, Stylus, Babel and Handlebars. It works with both inline code and external files.
Other
221 stars 60 forks source link

Non-existent directory structure causes fatal errors #88

Closed joostrijneveld closed 8 years ago

joostrijneveld commented 8 years ago

I'm trying to use django-static-precompiler to compile LESS stylesheets. I've installed the Debian package node-less, which has provided me with the lessc compiler.

When I try to compile a LESS file called e.g. css/style.less (in a static directory), however, I get the following error:

static_precompiler.exceptions.StaticCompilationError: Error: ENOENT, no such file or directory ' [...] /static/COMPILED/css'
    at fs.mkdirSync (fs.js:651:18)
    at ensureDirectory (/usr/bin/lessc:190:9)
    at /usr/bin/lessc:236:21
    at Object.finish [as _finish] (/usr/lib/nodejs/less/parser.js:478:21)
    at Object.subFinish [as _finish] (/usr/lib/nodejs/less/import-visitor.js:56:47)
    at Object.tree.importVisitor.run (/usr/lib/nodejs/less/import-visitor.js:25:22)
    at /usr/lib/nodejs/less/import-visitor.js:63:34
    at /usr/lib/nodejs/less/parser.js:97:17
    at /usr/lib/nodejs/less/index.js:141:13
    at finish (/usr/lib/nodejs/less/parser.js:478:21)

It does create the /static/ folder when executing this, but does not create COMPILED folder. Everything works fine when I manually create the static/COMPILED folder; it will then create the css folder itself.

When I then try to compile a LESS file that is not nested in a subfolder, i.e. directly accessible as a static file, it works when the static directory already exists: in that case it is able to create the COMPILED directory by itself.

From all of the above, I observe that it is trying to create the nested path to store the compiled LESS files, but is only able to create 1 subdirectory. For some reason, creation of multiple subdirectories fails.

joostrijneveld commented 8 years ago

So, it turns out the problem is with (dependencies of) lessc. In particular, this line requires the mkdirp package, and otherwise falls back to mkdirSync, as is seen in my stacktrace. By installing mkdirp (e.g. node-mkdirp via apt), it is now able to create full paths, and everything is golden.

The crucial difference is that mkdirp, as opposed to mkdirSync, creates full paths.