-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected
6.4+
Description
I am migrating some code from using webpack encore to assetmapper.
I found a very strange behavior and debugged it for a long time. Everything seems to work with assetmapper but the browser still shows a 404 error when importing relative js and css files from app.js like this:
...
//this is for symfony ux
import './bootstrap.js';
...When looking at the network tab in the browser it would still download the bootstrap.js file (with the correct version hash). And also the importmap looked good:
<script type="importmap">
{
"imports": {
...
"/assets/bootstrap.js?v=dev": "/assets/bootstrap-209b7ad405377c6efaf2dffd7b3feba1.js?v=dev",
...What I did not saw at first (as I'm new to assetmapper) - there is a ?v=dev in the urls. That didnt bother me too much.
Turns out, that was the problem.
Because when you activate asset versioning with the symfony framework like here: https://symfony.com/doc/current/reference/configuration/framework.html#version
it adds the version string to all the generated urls. Which then doesnt match with actual URLs from the in-browser executed app.js anymore.
My framework/assets configuration looked like this:
framework:
assets:
version: 'dev'
version_format: '%%s?v=%%s'Disabling the whole assets configuration solved my problem.
It might be a good thing to point to this problem in the documentation of assetmapper or somehow solve this so the url-generation in importmap would not use the asset versioning feature even if its turned on.
Cheers
Markus
How to reproduce
- Use basic Assetmapper set up
- Enable asset versioning:
in config/packages/framework.yml
framework:
assets:
version: 'dev'
version_format: '%%s?v=%%s'- Import a relative file in app.js
...
//this is for symfony ux
import './bootstrap.js';
...- See 404 errors in the browser
Possible Solution
Disable framework asset versioning.
Additional Context
No response