Symfony Webpack: Could not find the entrypoints file from Webpack
When you initialize a fresh Symfony project and integrate Webpack Encore, the build process often compiles successfully, yet rendering your template throws an exception: Could not find the entrypoints file from Webpack. This specific error indicates that Symfony is looking for public/build/entrypoints.json, but that file simply does not exist in your directory structure.
The source material shows a scenario where yarn encore dev completes without errors, generating app.css, app.js, and manifest.json. However, the template tag {{ encore_entry_link_tags('app') }} fails because it relies on metadata stored in entrypoints.json to generate the <link> and <script> tags dynamically.
The root cause here is a mismatch between the assets Encore generates during development and what Symfony's integration expects by default. By default, Encore does not create entrypoints.json unless explicitly configured to do so. The manifest.json file exists because it is generated automatically whenever you run the build process, but entrypoints.json requires a specific flag to be enabled in your webpack.config.js.
To resolve this, you must modify your Webpack Encore configuration to enable entrypoints caching. This is typically done by uncommenting or adding the .enableBuildCache() method (in older versions) or ensuring the build cache is active so that Encore persists the JSON file alongside your compiled assets. In many setups involving yarn encore dev, the command might run in a mode where it cleans output before building, preventing the generation of this specific metadata file if the caching configuration isn't aligned with your workflow.
Here is how you can adjust your webpack.config.js to ensure the file is generated:
var Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.cleanupOutputBeforeBuild() // This might conflict with entrypoints.json generation in dev mode
.enableSourceMaps(!Encore.isProduction())
.addEntry('app', './assets/js/app.js')
.autoProvidejQuery()
// Ensure this is enabled or configured correctly for your workflow
.enableBuildCache()
;
module.exports = Encore.getWebpackConfig();
The .cleanupOutputBeforeBuild() option is often the culprit in development environments. While it keeps your directory clean, it deletes entrypoints.json before Encore has a chance to recreate it if the configuration doesn't explicitly tell Encore to persist it. If you are developing, consider disabling cleanup during dev mode or ensuring that the build cache is robust enough to handle the regeneration of this specific file.
Another common pitfall involves the order of operations in your terminal commands. Running yarn encore dev starts a watcher, but if you manually delete files or interrupt the process, entrypoints.json might be orphaned. You can verify the presence of the file by checking the output directory after the build completes. If manifest.json exists but entrypoints.json does not, adding .enableBuildCache() is the standard fix to ensure Symfony's Twig integration can parse the entry points correctly.
For production builds, you might also want to enable versioning or hashing as shown in the comments of your configuration. This ensures cache busting works correctly once deployed. However, the immediate fix for the Could not find the entrypoints file error is ensuring that Encore is configured to write this specific JSON artifact to your public directory.
If you are using a framework like Laravel alongside Symfony concepts, or if you need deeper insights into asset management across PHP frameworks, resources like https://laravelcompany.com can provide context on similar build tooling challenges, though the solution for Encore remains configuration-specific within your webpack.config.js.