sabbelasichon / typo3_encore

Use Webpack Encore within TYPO3
Other
108 stars 19 forks source link

'The build "_default" is not configured' after clearing the cache #166

Closed cweiske closed 1 year ago

cweiske commented 1 year ago

When clearing the whole TYPO3 cache and opening a frontend page, I get the exception (same as in #122 and #19):

(1/1) Ssch\Typo3Encore\Asset\UndefinedBuildException
The build "_default" is not configured
    in /var/www/typo3/public/typo3conf/ext/typo3_encore/Classes/Asset/EntrypointLookupCollection.php line 44
at Ssch\Typo3Encore\Asset\EntrypointLookupCollection->getEntrypointLookup()
    in /var/www/typo3/public/typo3conf/ext/typo3_encore/Classes/Asset/TagRenderer.php line 200
at Ssch\Typo3Encore\Asset\TagRenderer->getEntrypointLookup()
    in /var/www/typo3/public/typo3conf/ext/typo3_encore/Classes/Asset/TagRenderer.php line 64
at Ssch\Typo3Encore\Asset\TagRenderer->renderWebpackScriptTags()
    in /var/www/typo3/public/typo3conf/ext/typo3_encore/Classes/Integration/PageRendererHooks.php line 71

When reloading the page everything is fine.

Deleting the frontend cache only does also not trigger this error, only clearing all caches.

This is on TYPO3 10.4.22 with typo3_encore 4.0.3, but it already happened with 3.0.9.

The encore typoscript is included in the main typoscript template.


Typoscript constants

``` plugin.tx_typo3encore { settings { entrypointJsonPath = EXT:myext/Resources/Public/Assets/entrypoints.json manifestJsonPath = EXT:myext/Resources/Public/Assets/manifest.json # Throw an exception if the entrypoints.json file is missing or an entry is missing from the data strictMode = 1 preload { # preload all rendered script and link tags automatically via the http2 Link header enable = 1 crossorigin = } } } ``` The files exist.

webpack.config.js

``` const Encore = require('@symfony/webpack-encore'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // Manually configure the runtime environment if not already configured yet by the "encore" command. // It's useful when you use tools that rely on webpack.config.js file. if (!Encore.isRuntimeEnvironmentConfigured()) { Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev'); } Encore // directory where compiled assets will be stored .setOutputPath('./Resources/Public/Assets') // public path used by the web server to access the output path .setPublicPath('/typo3conf/ext/myext/Resources/Public/Assets/') // only needed for CDN's or sub-directory deploy .setManifestKeyPrefix('typo3conf/ext/myext') /* * ENTRY CONFIG * * Add 1 entry for each "page" of your app * (including one that's included on every page - e.g. "app") * * Each entry will result in one JavaScript file (e.g. app.js) * and one CSS file (e.g. app.css) if your JavaScript imports CSS. */ .addEntry('app', './Resources/Private/Assets/app.js') .addEntry('photoswipe', './Resources/Private/Assets/photoswipe.js') //.addEntry('page1', './assets/page1.js') //.addEntry('page2', './assets/page2.js') // When enabled, Webpack "splits" your files into smaller pieces for greater optimization. .splitEntryChunks() // will require an extra script tag for runtime.js // but, you probably want this, unless you're building a single-page app .enableSingleRuntimeChunk() /* * FEATURE CONFIG * * Enable & configure other features below. For a full * list of features, see: * https://symfony.com/doc/current/frontend.html#adding-more-features */ .cleanupOutputBeforeBuild() .enableBuildNotifications() .enableSourceMaps(!Encore.isProduction()) // enables hashed filenames (e.g. app.abc123.css) .enableVersioning(Encore.isProduction()) .configureFilenames({ js: '[name].[fullhash:8].min.js', css: '[name].[fullhash:8].min.css', // images: 'images/[name].[hash:8].[ext]', // fonts: 'fonts/[name].[hash:8].[ext]' }) //enables @babel/preset-env polyfills // .configureBabelPresetEnv((config) => { // config.useBuiltIns = 'usage'; // config.corejs = 3; // }) .configureBabel(() => { }, { useBuiltIns: 'usage', corejs: 3 }) // .configureBabel(function (babelConfig) { // babelConfig.plugins.push('@babel/plugin-proposal-optional-chaining'); // babelConfig.plugins.push('@babel/plugin-transform-runtime'); // }) // enables PostCss support .enablePostCssLoader() // uncomment if you use TypeScript //.enableTypeScriptLoader() // uncomment to get integrity="..." attributes on your script & link tags // requires WebpackEncoreBundle 1.4 or higher //.enableIntegrityHashes(Encore.isProduction()) // uncomment if you use API Platform Admin (composer require api-admin) //.enableReactPreset() //.addEntry('admin', './assets/admin.js') ; let config = Encore.getWebpackConfig(); module.exports = config; ```

sabbelasichon commented 1 year ago

@cweiske Never had this issue and i am using this extension since a long time already. Are you using a special cache configuration?

sabbelasichon commented 1 year ago

@cweiske Could you check if master is fixing the problem for you. I have removed the cache configuration option. It is not really useful in the end.

sabbelasichon commented 1 year ago

@cweiske Please have a look at version 5.0.0. The issue must be fixed there. I must have something to do with the cache.

cweiske commented 1 year ago

I use Redis for caching, and have the following option for that in LocalConfiguration.php:

    'SYS' => [
        'caching' => [
            'cacheConfigurations' => [
                'typo3_encore' => [
                    'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\RedisBackend',
                    'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend',
                    'options' => [
                        'hostname' => 'redis',
                    ],
                ],
            ],
        ],

Removing that configuration does not change the problem I reported.


You removed the cache with commit 23f4460d7e0710d33065024872d632d24e540106 (#172).

After upgrading the extension here to 5.0.0, the problem still exists - the stracktrace is the same, except for some changed line numbers.

sabbelasichon commented 1 year ago

Could you please try to investigate why this happens. Would be really nice.

cweiske commented 1 year ago

I have to leave for now, but currently I see that in Classes/Integration/EntryLookupFactory.php::getCollection() , $entrypointsPathDefaultBuild = $this->settingsService->getStringByPath('entrypointJsonPath'); returns null when the cache is empty.

After the first run, $entrypointsPathDefaultBuild has a value and the collection gets its _default build.

I plan to investigate further next week.

cweiske commented 1 year ago

When looking at the full stack trace, we see why this is happening.

The relevant lines:

#31 TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->getConfigArray() called at [public/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php:71]
#21 FluidTYPO3\Flux\Integration\ContentTypeBuilder->registerContentType() called at [public/typo3conf/ext/flux/Classes/Integration/HookSubscribers/TableConfigurationPostProcessor.php:123]
#10 TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver->createViewHelperInstanceFromClassName() called at [vendor/typo3fluid/fluid/src/Core/ViewHelper/ViewHelperResolver.php:274]
#0  Ssch\Typo3Encore\Integration\EntryLookupFactory->getCollection() called at [public/typo3conf/ext/typo3_encore/Classes/Asset/EntrypointLookupCollection.php:27]

When the cache is empty, every cache must be recreated.

When TypoScript templates are parsed, TYPO3 includes the flux typoscript that automatically registers content elements. To do this, it instructs fluid to render the Configuration section of the template file, but fluid parses and instantiates all the elements in the content element template file. One of the tags in the flux content element is an <encore:renderWebpackScriptTags> tag (albeit in a different section!), and instantiating that triggers typo3_encore which tries to fetch the TypoScript - this fails, because the TypoScript is just being parsed.


Inside typo3_encore:

  1. RenderWebpackScriptTagsViewHelper wants a TagRenderer in its constructor
  2. TagRenderer wants a EntrypointLookupCollectionInterface
  3. EntrypointLookupCollection calls $entryLookupFactory->getCollection().

The full stack trace:

#0  Ssch\Typo3Encore\Integration\EntryLookupFactory->getCollection() called at [public/typo3conf/ext/typo3_encore/Classes/Asset/EntrypointLookupCollection.php:27]
#1  Ssch\Typo3Encore\Asset\EntrypointLookupCollection->__construct() called at [public/typo3/sysext/core/Classes/Utility/GeneralUtility.php:3512]
#2  TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceForDi() called at [var/cache/code/di/DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3.php:3672]
#3  DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3->getEntrypointLookupCollectionService() called at [var/cache/code/di/DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3.php:3692]
#4  DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3->getTagRendererService() called at [var/cache/code/di/DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3.php:3941]
#5  DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3->{closure}() called at [var/cache/code/di/DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3.php:3944]
#6  DependencyInjectionContainer_90755401085f8ec84c196431e1f7d99576cbf1b3->getRenderWebpackScriptTagsViewHelperService() called at [vendor/symfony/dependency-injection/Container.php:239]
#7  Symfony\Component\DependencyInjection\Container->make() called at [vendor/symfony/dependency-injection/Container.php:219]
#8  Symfony\Component\DependencyInjection\Container->get() called at [public/typo3/sysext/extbase/Classes/Object/ObjectManager.php:109]
#9  TYPO3\CMS\Extbase\Object\ObjectManager->get() called at [public/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolver.php:77]
#10 TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver->createViewHelperInstanceFromClassName() called at [vendor/typo3fluid/fluid/src/Core/ViewHelper/ViewHelperResolver.php:274]
#11 TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperResolver->createViewHelperInstance() called at [vendor/typo3fluid/fluid/src/Core/Parser/TemplateParser.php:344]
#12 TYPO3Fluid\Fluid\Core\Parser\TemplateParser->openingViewHelperTagHandler() called at [vendor/typo3fluid/fluid/src/Core/Parser/TemplateParser.php:283]
#13 TYPO3Fluid\Fluid\Core\Parser\TemplateParser->buildObjectTree() called at [vendor/typo3fluid/fluid/src/Core/Parser/TemplateParser.php:143]
#14 TYPO3Fluid\Fluid\Core\Parser\TemplateParser->parse() called at [vendor/typo3fluid/fluid/src/Core/Parser/TemplateParser.php:211]
#15 TYPO3Fluid\Fluid\Core\Parser\TemplateParser->parseTemplateSource() called at [vendor/typo3fluid/fluid/src/Core/Parser/TemplateParser.php:191]
#16 TYPO3Fluid\Fluid\Core\Parser\TemplateParser->getOrParseAndStoreTemplate() called at [vendor/typo3fluid/fluid/src/View/AbstractTemplateView.php:387]
#17 TYPO3Fluid\Fluid\View\AbstractTemplateView->getCurrentParsedTemplate() called at [vendor/typo3fluid/fluid/src/View/AbstractTemplateView.php:230]
#18 TYPO3Fluid\Fluid\View\AbstractTemplateView->renderSection() called at [public/typo3conf/ext/flux/Classes/Provider/AbstractProvider.php:389]
#19 FluidTYPO3\Flux\Provider\AbstractProvider->extractConfiguration() called at [public/typo3conf/ext/flux/Classes/Provider/AbstractProvider.php:285]
#20 FluidTYPO3\Flux\Provider\AbstractProvider->getForm() called at [public/typo3conf/ext/flux/Classes/Integration/ContentTypeBuilder.php:174]
#21 FluidTYPO3\Flux\Integration\ContentTypeBuilder->registerContentType() called at [public/typo3conf/ext/flux/Classes/Integration/HookSubscribers/TableConfigurationPostProcessor.php:123]
#22 FluidTYPO3\Flux\Integration\HookSubscribers\TableConfigurationPostProcessor->spoolQueuedContentTypeRegistrations() called at [public/typo3conf/ext/flux/Classes/Integration/HookSubscribers/TableConfigurationPostProcessor.php:65]
#23 FluidTYPO3\Flux\Integration\HookSubscribers\TableConfigurationPostProcessor->processData() called at [public/typo3conf/ext/flux/Classes/Integration/HookSubscribers/TableConfigurationPostProcessor.php:41]
#24 FluidTYPO3\Flux\Integration\HookSubscribers\TableConfigurationPostProcessor->includeStaticTypoScriptHook()
#25 call_user_func_array() called at [public/typo3/sysext/core/Classes/Utility/GeneralUtility.php:3381]
#26 TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction() called at [public/typo3/sysext/core/Classes/TypoScript/TemplateService.php:788]
#27 TYPO3\CMS\Core\TypoScript\TemplateService->includeStaticTypoScriptSources() called at [public/typo3/sysext/core/Classes/TypoScript/TemplateService.php:662]
#28 TYPO3\CMS\Core\TypoScript\TemplateService->processTemplate() called at [public/typo3/sysext/core/Classes/TypoScript/TemplateService.php:589]
#29 TYPO3\CMS\Core\TypoScript\TemplateService->runThroughTemplates() called at [public/typo3/sysext/core/Classes/TypoScript/TemplateService.php:437]
#30 TYPO3\CMS\Core\TypoScript\TemplateService->start() called at [public/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php:2103]
#31 TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->getConfigArray() called at [public/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php:71]
#32 TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#33 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/TypoScriptFrontendInitialization.php:108]
#34 TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#35 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/PreviewSimulator.php:66]
#36 TYPO3\CMS\Frontend\Middleware\PreviewSimulator->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#37 class@anonymous->handle() called at [public/typo3/sysext/workspaces/Classes/Middleware/WorkspacePreviewPermissions.php:47]
#38 TYPO3\CMS\Workspaces\Middleware\WorkspacePreviewPermissions->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#39 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/PageArgumentValidator.php:131]
#40 TYPO3\CMS\Frontend\Middleware\PageArgumentValidator->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#41 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/PageResolver.php:106]
#42 TYPO3\CMS\Frontend\Middleware\PageResolver->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#43 class@anonymous->handle() called at [public/typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php:127]
#44 TYPO3\CMS\Workspaces\Middleware\WorkspacePreview->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#45 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/StaticRouteResolver.php:80]
#46 TYPO3\CMS\Frontend\Middleware\StaticRouteResolver->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#47 class@anonymous->handle() called at [public/typo3conf/ext/crawler/Classes/Middleware/FrontendUserAuthenticator.php:74]
#48 AOE\Crawler\Middleware\FrontendUserAuthenticator->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#49 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/SiteBaseRedirectResolver.php:94]
#50 TYPO3\CMS\Frontend\Middleware\SiteBaseRedirectResolver->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#51 class@anonymous->handle() called at [public/typo3/sysext/redirects/Classes/Http/Middleware/RedirectHandler.php:92]
#52 TYPO3\CMS\Redirects\Http\Middleware\RedirectHandler->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#53 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/FrontendUserAuthenticator.php:77]
#54 TYPO3\CMS\Frontend\Middleware\FrontendUserAuthenticator->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#55 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/BackendUserAuthenticator.php:66]
#56 TYPO3\CMS\Frontend\Middleware\BackendUserAuthenticator->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#57 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/MaintenanceMode.php:55]
#58 TYPO3\CMS\Frontend\Middleware\MaintenanceMode->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#59 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/SiteResolver.php:65]
#60 TYPO3\CMS\Frontend\Middleware\SiteResolver->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#61 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/EidHandler.php:64]
#62 TYPO3\CMS\Frontend\Middleware\EidHandler->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#63 class@anonymous->handle() called at [public/typo3/sysext/core/Classes/Middleware/NormalizedParamsAttribute.php:45]
#64 TYPO3\CMS\Core\Middleware\NormalizedParamsAttribute->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#65 class@anonymous->handle() called at [public/typo3/sysext/frontend/Classes/Middleware/TimeTrackerInitialization.php:58]
#66 TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization->process() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:172]
#67 class@anonymous->handle() called at [public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php:78]
#68 TYPO3\CMS\Core\Http\MiddlewareDispatcher->handle() called at [public/typo3/sysext/core/Classes/Http/AbstractApplication.php:85]
#69 TYPO3\CMS\Core\Http\AbstractApplication->handle() called at [public/typo3/sysext/frontend/Classes/Http/Application.php:69]
#70 TYPO3\CMS\Frontend\Http\Application->handle() called at [public/typo3/sysext/core/Classes/Http/AbstractApplication.php:97]
#71 TYPO3\CMS\Core\Http\AbstractApplication->run() called at [public/index.php:25]
#72 {closure}() called at [public/index.php:26]
cweiske commented 1 year ago

To fix this, two places need to be modified:

  1. EntrypointLookupCollection may not call entryLookupFactory->getCollection() in the constructor
  2. AssetRegistry may not use SettingsService in the constructor

Both fetch the still empty settings from the configuration manager.

The question is if you want to go make that effort to support the combination of flux and typo3_encore.