Skip to content

No way for an extension to import a standard Less file because the reverse paths (../) in Less @import statements are forbidden for the extensions #2264

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

Closed
dmitrii-fediuk opened this issue Nov 5, 2015 · 5 comments
Assignees
Labels
Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@dmitrii-fediuk
Copy link

The problem is similar to #2179
#2179 is not actually a problem because of the solution I found and described there.
But when an extension need to import a standard Magento 2 Less file the solution will not help because of the folder structure:
var\view_preprocessed\css\adminhtml\Magento\backend\en_US:
--------css
--------Custom_Extenson
So the Custom_Extenson can not @import a Less file from the css folder (this is the folder with standard Magento 2 less files) as it can not use reverse paths.

@ksz2013
Copy link

ksz2013 commented Feb 4, 2016

Any news on this issue?

Is it possible to include core standard less files into our custom module. I am having the same problem as well.

File path '../../source/lib/_responsive.less' is forbidden for security reasons.

@eug123
Copy link
Contributor

eug123 commented Mar 1, 2016

internal ticket MAGETWO-48840 created

@alankent
Copy link

alankent commented Mar 1, 2016

First, yes - this needs fixing in M2. I think there is a workaround if you are using Grunt/Gulp (not our built in tool chain) if you want to experiement. I think if you declare a variable holding the path name then put that variable into the import path name (@mypath: '../blah.less' followed by @import '@{mypath}') then our code lets it through the magento dev:source-theme:deploy process and the 3rd party Less preprocessor expands the variable and does not complain about ".." in the path.

We are considering options such as having a "Lib::" prefix to go back to the root so you could @import 'Lib::source/lib/_responsive.less';. Its sort of like the module prefix we already support, but for the Magento library.

@MomotenkoNatalia MomotenkoNatalia added PS and removed CS labels Mar 3, 2016
@shiftedreality shiftedreality added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Mar 3, 2016
@leoquijano
Copy link

Hi,

I'm having a similar problem when trying to use a LESS file from the vendor/ directory. In my case, Im trying to use some mixins from the Bootstrap library in my theme file. So I have this in my theme's main.less file:

@import '../../../../../../../vendor/twbs/bootstrap/less/bootstrap.less';

Now, I could use Bootstrap compiled CSS, but that wouldn't allow me to use variables and mixins from that deployment. If I try to copy Bootstrap files directly in the theme web directory, then the LESS preprocessor will pick them up and fail, since it tries to compile every file in the Bootstrap library instead of just the main one (which imports the other ones).

(And also, it's better to keep external CSS libraries in the vendor directory, so they're also updated using Composer, or even Bower)

The error shown is the same as described above:

File path '../../../../../../vendor/twbs/bootstrap/less/bootstrap.less' is forbidden for security reasons.>

I tried to symlink the file (which is not always the best solution since some deployments may fail to reproduce symlinks adequately, especially on Windows), but it's not working either. I'll probably have to copy the full Bootstrap code in a file as a workaround, but it's more maintainable to enable some way of importing from vendor/ directory.

Any other suggestions?

@shiftedreality
Copy link
Member

Hi @leoquijano.

You're correct. There is no possibility to import files from vendor directory.
We've added possibility to import files from standard Magento lib directory in
https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Simple.php

via ././ to cover current case

If importing files from vendor directory still valuable case for you, please create new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

7 participants