Problem using @Import rule to import a CSS which has nested @Import rules
See original GitHub issueHaving 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/4.42.0_webpack@4.42.0/node_modules/webpack/lib/Compilation.js:925:10
at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/4.42.0_webpack@4.42.0/node_modules/webpack/lib/NormalModuleFactory.js:401:22
at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/4.42.0_webpack@4.42.0/node_modules/webpack/lib/NormalModuleFactory.js:130:21
at /Users/soroosh/Downloads/my-project/node_modules/.pnpm/registry.npmjs.org/webpack/4.42.0_webpack@4.42.0/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/4.42.0_webpack@4.42.0/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/4.2.1_webpack@4.42.0/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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
import - CSS: Cascading Style Sheets - MDN Web Docs
Imported rules must come before all other types of rules, except @charset rules and layer creating @layer statements. The @import rule is not...
Read more >Sass: @import
The imported CSS is nested in that context, which makes nested imports useful for scoping a chunk of CSS to a particular element...
Read more >Import of less files into a limited scope - css
Since this question was posted and answered, pre-processors have implemented @import with scope. This now works in LESS, SASS and Stylus. example:
Read more >429905 β [CSS] Nested @import silently fail - Bugs - Eclipse
Using nested imports into a CSS stylesheet is not working and does not throw any error in console. Related also to Bug 423744....
Read more >no-invalid-position-at-import-rule
Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer ), or else the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue is the same as reported for the extract-loader peerigon/extract-loader#48
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:
We can have the structure with styles.css
with shared-imports.css
with view-imports.css
but we can not have an import in a sub directory so having for instance styles.css
where main-view.css
this will fail as it cant find the loaders.