question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'css-loader' can't resolve the relative path in production mode since 14.6.0

See original GitHub issue

Description of the bug / feature

‘css-loader’ can’t resolve the relative path in production mode.

Minimal reproducible example

  • My frontend folder looks like this:
-resources
  -frontend
    -css
        leaflet-map-styles.css
  -img
     map_layers_icon.png
  • leaflet-map-styles.css
[class="leaflet-control-layers-toggle"] {
	background-image: url('img/map_layers_icon.png') !important;
	background-size: 26px 26px;
}
  • GoogleMap.java
@CssImport(value = "./css/leaflet-map-styles.css", themeFor = "leaflet-map")
public class GoogleMap extends Div {...}

Expected behavior

No problem when running/building image

Actual behavior

ERROR in ../node_modules/@vaadin/flow-frontend/css/leaflet-map-styles.css
Module build failed (from ../node_modules/css-loader/dist/cjs.js):
Error: Can't resolve 'img/map_layers_icon.png' in 'D:\test\node_modules\@vaadin\flow-frontend\css'
    at D:\test\node_modules\enhanced-resolve\lib\Resolver.js:209:21
    at D:\test\node_modules\enhanced-resolve\lib\Resolver.js:285:5
    
    ...
    
@ ../target/frontend/generated-flow-imports-fallback.js 33:0-71 34:89-96
@ ../target/frontend/generated-flow-imports.js?babel-target=es6

...

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18:38 min
[INFO] Finished at: 2021-05-18T13:23:50+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:14.6.1:build-frontend (default) on project test: Webpack process exited with non-zero exit code.
[ERROR] Stderr: ''
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.vaadin:vaadin-maven-plugin:14.6.1:build-frontend (default) on project test: Webpack process exited with non-zero exit code.
Stderr: ''
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    
    ...    

Versions:

- Vaadin / Flow version: 14.6.1 (brokenness starts with 14.6.0)
- Java version: 11
- OS version: Windows 10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
caaladorcommented, May 26, 2021

The fix will come in 14.6.2

Closing issue as the fix has been merged and it should roll out sometime soon.

Until release of 14.6.2 you can in the mean while add the raw-loader dependency to a java class with @NpmPackage(value = "raw-loader", version = "3.1.0") and then adding to webpack.config.js the lines

if(flowDefaults.module.rules[2].test.toString().includes('.css')) {
  flowDefaults.module.rules[2].use = [ {loader: 'raw-loader' }];
} else if(flowDefaults.module.rules[1].test.toString().includes('.css')) {
  flowDefaults.module.rules[1].use = [ {loader: 'raw-loader' }];
}
0reactions
vaadin-botcommented, Aug 9, 2021

This ticket/PR has been released with platform 14.7.0.alpha3 and is also targeting the upcoming stable 14.7.0 version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'css-loader' can't resolve the relative path in production mode since ...
'css-loader' can't resolve the relative path in production mode. Minimal reproducible example. My frontend folder looks like this: -resources -frontend -css ...
Read more >
css-loader can not resolve urls generated by file-loader
So look like css-loader with turned on css-modules wants url paths as a node relative paths with ./ , not just as a...
Read more >
webpack can't resolve 'path' | The AI Search Engine You Control
If you're just generating CSS without passing it to the css-loader , it must be relative to your web root. You will be...
Read more >
css-loader | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
API - ESBuild
External paths are applied both before and after path resolution, ... For example, the js loader interprets the file as JavaScript and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found