Skip to content
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

Problem using @Import rule to import a CSS which has nested @Import rules #9794

Closed
taefi opened this issue Jan 12, 2021 · 7 comments
Closed

Comments

@taefi
Copy link
Contributor

taefi commented Jan 12, 2021

Having the following project structure:

frontend/
|_ themes/
    |_ custom-theme/
        |_ app-styles/
        |   |_ views/
        |       |_ helloworld/
        |       |   |_ hello-world-style.css
        |       |_ masterdetail/
        |       |   |_ master-detail-style.css
        |       |_ view-styles.css
        |_ styles.css     

If view-styles.css contains @Imports like this:

@Import "./helloworld/hello-world-style.css";
@Import "./masterdetail/master-detail-style.css";

and import this file into styles.css, like this:

@Import "./app-styles/views/view-styles.css";

The application starts, but frontend errors appears like this:

ERROR in ./themes/custom-theme/styles.css
Module build failed (from ../node_modules/.pnpm/registry.npmjs.org/extract-loader/5.1.0/node_modules/extract-loader/lib/extractLoader.js):
ModuleNotFoundError: Module not found: Error: Can't resolve '../../../../../node_modules/@vaadin/theme-loader/theme-loader.js' in '/Users/soroosh/Downloads/my-project/frontend/themes/custom-theme'
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/[email protected]/node_modules/webpack/lib/Compilation.js:925:10
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/[email protected]/node_modules/webpack/lib/NormalModuleFactory.js:401:22
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/[email protected]/node_modules/webpack/lib/NormalModuleFactory.js:130:21
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/[email protected]/node_modules/webpack/lib/NormalModuleFactory.js:224:22
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/neo-async/2.6.2/node_modules/neo-async/async.js:2830:7
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/neo-async/2.6.2/node_modules/neo-async/async.js:6877:13
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/neo-async/2.6.2/node_modules/neo-async/async.js:2830:7
    at done (/Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/neo-async/2.6.2/node_modules/neo-async/async.js:2925:13)
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/[email protected]/node_modules/webpack/lib/NormalModuleFactory.js:449:23
    at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/enhanced-resolve/4.5.0/node_modules/enhanced-resolve/lib/Resolver.js:213:14
 @ ./themes/custom-theme/custom-theme.generated.js 10:0-37 22:20-29
 @ ../target/flow-frontend/themes/theme-generated.js
 @ ./generated/vaadin.ts

ERROR in ./themes/custom-theme/styles.css
Module not found: Error: Can't resolve '../../../../../node_modules/@vaadin/theme-loader/theme-loader.js' in '/Users/soroosh/Downloads/my-project/frontend/themes/custom-theme'
 @ ./themes/custom-theme/styles.css -!../../../../../node_modules/.pnpm/registry.npmjs.org/css-loader/[email protected]/node_modules/css-loader/dist/cjs.js??ref--5-2!../../../../../node_modules/@vaadin/theme-loader/theme-loader.js??ref--5-3!/Users/soroosh/Downloads/my-project/frontend/themes/custom-theme/app-styles/views/addressform/address-form-view.css
 @ ./themes/custom-theme/custom-theme.generated.js
 @ ../target/flow-frontend/themes/theme-generated.js
 @ ./generated/vaadin.ts

Simply by removing the imports from view-styles.css the theme styles are being applied and only the view-specific styles are missing (which are not imported). Also by importing the view-specific styles directly into the styles.css it works without a problem.

Desired Behaviour:

To be able to use @Import rules in CSS files that have nested @Import rules.

Environment:

Vaadin: 19.0-SNAPSHOT
Flow: 6.0-SNAPSHOT
Vaadin-Spring: 16.0-SNAPSHOT
OS: MacOS BigSur 11.1
Browser: Chrome 87.0.4280.88
@caalador
Copy link
Contributor

I noted while researching that you can have nested imports if the importer is located at the root level.
So having the theme structure with the files:

themes
└── my-theme
    ├── views
    │   ├── views-shared.css
    │   ├── main-view.css
    │   └── payments
    │      └── payment-view.css
    ├── view-imports.css
    ├── shared-imports.css
    └── styles.css

We can have the structure
with styles.css

@import url('shared-imports.css');

with shared-imports.css

@import url('views/views-shared.css');
@import url('view-imports.css');

with view-imports.css

@import url('views/main-view.css'):
@import url('views/payments/payment-view.css');

but we can not have an import in a sub directory so having for instance
styles.css

@import url('views/main-view.css');

where main-view.css

@import url('views-shared.css');

this will fail as it cant find the loaders.

@caalador
Copy link
Contributor

Seems that this is from the extract-loader because if I remove it then all import versions compile fine.

@caalador
Copy link
Contributor

This issue is the same as reported for the extract-loader peerigon/extract-loader#48

caalador added a commit to vaadin/docs that referenced this issue Jan 14, 2021
caalador added a commit to vaadin/docs that referenced this issue Jan 14, 2021
@pleku pleku added this to the Custom Theme Feature milestone Jan 14, 2021
@caalador caalador removed their assignment Jan 14, 2021
taefi pushed a commit to vaadin/docs that referenced this issue Jan 15, 2021
@pleku pleku added the blocked label Jan 28, 2021
@pleku
Copy link
Contributor

pleku commented Jan 28, 2021

Just noting that this issue is waiting for extract-loader issue to be fixed and documented for now.

@Artur-
Copy link
Member

Artur- commented Feb 17, 2022

Will this be resolved by moving to Vite?

@caalador
Copy link
Contributor

Probably as we don't need the extract-loader with Vite.

@Artur-
Copy link
Member

Artur- commented Apr 19, 2023

This was a problem only in webpack

@Artur- Artur- closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants