I have created a custom theme in Magento 2 and I want to add _customvariables.less and _custommixins.less in all other less files.

I have added these files in the following location.


I have created separate less files for different areas like customer-account,cms-pages,category-pages,product-pages now when I tried to import _customvariables.less and _custommixins.less via following code

@import '../../../Magento_Theme/web/css/source/_variables.less';
@import '../../../Magento_Theme/web/css/source/_mixins.less';

I have got following errors in system.log

[2018-06-29 12:55:43] main.CRITICAL: File path 'magento2/app/design/frontend/Vendor/theme1/Magento_Cms/web/../../Magento_Theme/web/css/source/_variables.less' is forbidden for security reasons. [] []

When i try to run php -dmemory_limit=6G bin/magento setup:static-content:deploy -f then i found follwoing errors in cli

Compilation from source: magento2/app/design/frontend/Vendor/theme1/web/css/media.less . File path 'magento2/app/design/frontend/Vendor/default/web/../Magento_Theme/web/css/source/_custommixins.less' is forbidden for security reasons.

I am using Koala for less compilation it successfully compiles with the @import but when we clean the pub/static directory or deploy static content the CSS files are not created properly.

I have read this thread (How can I custom less file and compile less file in magento 2), but in my case the _custommixins.less and the files which imports are in different directories like

File which imports : magento2/app/design/frontend/Vendor/theme1/Magento_Customer/web/css/source/customer_acc.less
File which need to import : magento2/app/design/frontend/Vendor/theme1/Magento_Theme/web/css/source/_custommixins.less

Currently, I'm not using grunt/gulp.


1 Answer 1


Create folder named module in magento2/app/design/frontend/Vendor/theme1/Magento_Theme/web/css/source/ folder and add _customvariables.less and _custommixins.less files in this folder.

Then import these two files in magento2/app/design/frontend/Vendor/theme1/Magento_Theme/web/css/source/_module.less file like below:

@import 'module/_customvariables.less';
@import 'module/_custommixins.less';

Run command php bin/magento s:up and php bin/magento s:s:d -f

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.