mariusbalcytis / webpack-bundle

Bundle to Integrate Webpack into Symfony
MIT License
122 stars 36 forks source link

Unknown "profiler_dump" function in "Symfony/../SecurityBundle/../Collector/security.html.twig" at line 180. #15

Closed lakhman closed 8 years ago

lakhman commented 8 years ago

I've got this working in development, but when I run the compile command for production, I get the following error:

Main error:

[Twig_Error_Syntax]                                                                           
Unknown "profiler_dump" function in 
"/app/vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig" at line 180.   

Full output:

$ console maba:webpack:compile --env=prod -vvv

  [Maba\Bundle\WebpackBundle\Exception\ResourceParsingException]  
  Got twig syntax exception while parsing                         

Exception trace:
 () at /app/vendor/maba/webpack-bundle/src/AssetProvider/TwigAssetProvider.php:63
 Maba\Bundle\WebpackBundle\AssetProvider\TwigAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/CollectionResourceAssetProvider.php:38
 Maba\Bundle\WebpackBundle\AssetProvider\CollectionResourceAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/CollectionResourceAssetProvider.php:38
 Maba\Bundle\WebpackBundle\AssetProvider\CollectionResourceAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/DynamicAssetProvider.php:39
 Maba\Bundle\WebpackBundle\AssetProvider\DynamicAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/CollectionResourceAssetProvider.php:38
 Maba\Bundle\WebpackBundle\AssetProvider\CollectionResourceAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/Service/AssetCollector.php:25
 Maba\Bundle\WebpackBundle\Service\AssetCollector->getAssets() at /app/vendor/maba/webpack-bundle/src/Config/WebpackConfigManager.php:46
 Maba\Bundle\WebpackBundle\Config\WebpackConfigManager->dump() at /app/vendor/maba/webpack-bundle/src/Compiler/WebpackCompiler.php:49
 Maba\Bundle\WebpackBundle\Compiler\WebpackCompiler->compile() at /app/vendor/maba/webpack-bundle/src/Command/CompileCommand.php:36
 Maba\Bundle\WebpackBundle\Command\CompileCommand->execute() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:834
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:186
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
 Symfony\Component\Console\Application->run() at /app/bin/console:28

  [Twig_Error_Syntax]                                                                           
  Unknown "profiler_dump" function in "/app/vendor/symfony/symfony/s  
  rc/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig" at line 180.   

Exception trace:
 () at /app/vendor/twig/twig/lib/Twig/ExpressionParser.php:574
 Twig_ExpressionParser->getFunctionNodeClass() at /app/vendor/twig/twig/lib/Twig/ExpressionParser.php:351
 Twig_ExpressionParser->getFunctionNode() at /app/vendor/twig/twig/lib/Twig/ExpressionParser.php:144
 Twig_ExpressionParser->parsePrimaryExpression() at /app/vendor/twig/twig/lib/Twig/ExpressionParser.php:84
 Twig_ExpressionParser->getPrimary() at /app/vendor/twig/twig/lib/Twig/ExpressionParser.php:41
 Twig_ExpressionParser->parseExpression() at /app/vendor/twig/twig/lib/Twig/ExpressionParser.php:93
 Twig_ExpressionParser->parseConditionalExpression() at /app/vendor/twig/twig/lib/Twig/ExpressionParser.php:59
 Twig_ExpressionParser->parseExpression() at /app/vendor/twig/twig/lib/Twig/Parser.php:144
 Twig_Parser->subparse() at /app/vendor/twig/twig/lib/Twig/TokenParser/For.php:40
 Twig_TokenParser_For->parse() at /app/vendor/twig/twig/lib/Twig/Parser.php:187
 Twig_Parser->subparse() at /app/vendor/twig/twig/lib/Twig/TokenParser/If.php:34
 Twig_TokenParser_If->parse() at /app/vendor/twig/twig/lib/Twig/Parser.php:187
 Twig_Parser->subparse() at /app/vendor/twig/twig/lib/Twig/TokenParser/Block.php:38
 Twig_TokenParser_Block->parse() at /app/vendor/twig/twig/lib/Twig/Parser.php:187
 Twig_Parser->subparse() at /app/vendor/twig/twig/lib/Twig/Parser.php:100
 Twig_Parser->parse() at /app/vendor/twig/twig/lib/Twig/Environment.php:619
 Twig_Environment->parse() at /app/vendor/maba/webpack-bundle/src/AssetProvider/TwigAssetProvider.php:60
 Maba\Bundle\WebpackBundle\AssetProvider\TwigAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/CollectionResourceAssetProvider.php:38
 Maba\Bundle\WebpackBundle\AssetProvider\CollectionResourceAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/CollectionResourceAssetProvider.php:38
 Maba\Bundle\WebpackBundle\AssetProvider\CollectionResourceAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/DynamicAssetProvider.php:39
 Maba\Bundle\WebpackBundle\AssetProvider\DynamicAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/AssetProvider/CollectionResourceAssetProvider.php:38
 Maba\Bundle\WebpackBundle\AssetProvider\CollectionResourceAssetProvider->getAssets() at /app/vendor/maba/webpack-bundle/src/Service/AssetCollector.php:25
 Maba\Bundle\WebpackBundle\Service\AssetCollector->getAssets() at /app/vendor/maba/webpack-bundle/src/Config/WebpackConfigManager.php:46
 Maba\Bundle\WebpackBundle\Config\WebpackConfigManager->dump() at /app/vendor/maba/webpack-bundle/src/Compiler/WebpackCompiler.php:49
 Maba\Bundle\WebpackBundle\Compiler\WebpackCompiler->compile() at /app/vendor/maba/webpack-bundle/src/Command/CompileCommand.php:36
 Maba\Bundle\WebpackBundle\Command\CompileCommand->execute() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:834
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:186
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
 Symfony\Component\Console\Application->run() at /app/bin/console:28

maba:webpack:compile [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

Any ideas why it's trying to load the collector when compiling for production? I've checked my configuration against the demo bundle of this project (which runs as expected). I can't seem to find any obvious differences. (Configuration is exactly the same - the default symfony config).

lakhman commented 8 years ago

I can reproduce this issue with a fresh new symfony install.

(You can copy and paste this into your terminal in one go to get up and running with the same error).

PROJECT_NAME=webpack-adminlte && echo $PROJECT_NAME
WORKING_DIR=~/Sites && echo $WORKING_DIR

cd $WORKING_DIR

# Create a new symfony 3 project && enter it
symfony new $PROJECT_NAME && cd $PROJECT_NAME

# Install webpack-bundle
composer require maba/webpack-bundle

# Update AppKernel.php
cat <<'-EOF' > app/AppKernel.patch
--- a/app/AppKernel.php
+++ b/app/AppKernel.php
@@ -15,6 +15,7 @@ class AppKernel extends Kernel
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
+            new Maba\Bundle\WebpackBundle\MabaWebpackBundle(),
            new AppBundle\AppBundle(),
        ];
-EOF

# Patch the AppKernel with our new bundle
patch -p1 -l < app/AppKernel.patch && rm app/AppKernel.patch

# Setup maba
yes | console maba:webpack:setup

# Make our entry file
mkdir -p app/Resources/assets && touch app/Resources/assets/main.js

# Compile the assets for the first time
console maba:webpack:compile --env=prod

# Fails here with the above error
# Why?
mariusbalcytis commented 8 years ago

It parses all twig files found in /Resources/views of each registered bundle. SecurityBundle/Resources/views/Collector/security.html.twig template is used for displaying information in web profiler, this is used only in development environment. The twig function used in that template, profiler_dump, is registered in WebProfilerBundle, which is loaded only in dev environment by default (in AppKernel class).

Temporary solution would be to enable parsing twig templates only in some bundles/directories:

maba_webpack: 
  asset_providers: 
    - 
      resource: 
        - ApplicationBundle # or any other bundles, where webpack_asset function can be found
        - AcmeHelloBundle
      type: twig_bundles
    - 
      resource: "%kernel.root_dir%/Resources/views"
      type: twig_directory

I'll look into some permanent solution inside the bundle itself. Probably just ignoring twig files with such an issue would be the best solution - they would not render either way in that environment, so no point in getting possible entry points from them.

lakhman commented 8 years ago

that worked, remember to clear your cache after updating (for prod), Thanks!

Yeah the solution to ignore these if they cause errors would be best, although perhaps we should display that to the user - we don't want to silently ignore errors (which may affect the user).

Awesome, that will do for now!

mariusbalcytis commented 8 years ago

With last fix default configuration should do just fine.

With default monolog configuration logger's warnings are displayed in console, so any failures will be visible to the developer, too.

New option was added for suppress_errors and set as default for prod (non-dev) environment. It ignores just those errors that can happen in this use-case.

lakhman commented 8 years ago

Awesome, just updated, works great, thanks.