Slim 4 & Webpack Error manifest file not exists

I am setting up Slim 4 PHP application and I am building JS & CSS with Webpack 4. I followed code from Github and Slim tutorial but I always get the error:

Type: Twig\Error\LoaderError
Code: 0
Message: Webpack manifest file not exists.

My layout.twig file is failing on this line :

{% webpack_entry_js ‘vendor’ %}

and my webpack.config.js file contains:


    const path = require('path');
    // const webpack = require('webpack');
    const { CleanWebpackPlugin } = require('clean-webpack-plugin');
    const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
    const MiniCssExtractPlugin = require('mini-css-extract-plugin');
    
    module.exports = (env, argv) => ({
        entry: {
            vendor: path.resolve(__dirname, './frontend/vendor/vendor.js'),
            layout: path.resolve(__dirname, './frontend/layout/layout.js')
        },
    
        output: {
            path: path.resolve(__dirname, 'public/assets'),
            publicPath: 'assets/',
            filename: '[name].bundle.js'
        },
    
        mode: 'production',    
    
        optimization: {
            splitChunks: {
                chunks: 'all',
                minSize: 20000,
                automaticNameDelimiter: '_'
            }        
        },
    
        performance: {
            maxEntrypointSize: 1024000,
            maxAssetSize: 1024000
        },
    
        resolve: {
            extensions: ['.js', '.ts', '.tsx', '.css', '.scss']
        },
    
        module: {
            rules: [
                {
                    test: /\.(png|jpg)$/,
                    use: [
                        'file-loader'
                    ]
                },            
                {
                    test: /\.js$/,
                    use: 'babel-loader',
                    exclude: /node_modules/
                },
                {
                    test: /\.tsx?$/,
                    use: ['babel-loader', 'ts-loader'],
                    exclude: /node_modules/
                },            
                {
                    test: /\.css$/,
                    use: [
                        MiniCssExtractPlugin.loader, 'css-loader'
                    ]
                },
                {
                    test: /\.scss$/,
                    use: [
                        MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'
                    ]
                },            
                {
                    test: /\.(ttf|eot|svg|woff|woff2)(\?[\s\S]+)?$/,
                    include: path.resolve(__dirname, './node_modules/@fortawesome/fontawesome-free/webfonts'),
                    use: {
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]',
                            outputPath: 'webfonts',
                            publicPath: '../webfonts',
                        },
                    }
                },
            ],
        },
    
        plugins: [
            new CleanWebpackPlugin(),
            new WebpackManifestPlugin({chunk: true, isChunk: true}),
            new MiniCssExtractPlugin({
                ignoreOrder: false,
                filename: '[name].bundle.css'
            }),
        ],
    
        watchOptions: {
            ignored: ['./node_modules/']
        }
    });

When I run webpack compailer as: npx webpack --watch it works. Inside /public/assets folder I see compiled files.
Here is also package.json file:

 "dependencies": {
    "@fortawesome/fontawesome-free": "^5.15.1",
    "@popperjs/core": "^2.6.0",
    "bootstrap": "^4.5.3",
    "jquery": "^3.5.1",
    "lodash": "^4.17.20"
},
"devDependencies": {
    "@babel/core": "^7.11.6",
    "@babel/preset-env": "^7.12.11",
    "@babel/preset-react": "^7.12.10",
    "babel-loader": "^8.1.0",
    "clean-webpack-plugin": "^3.0.0",
    "css-loader": "^5.0.1",
    "file-loader": "^6.2.0",
    "mini-css-extract-plugin": "^1.3.3",
    "node-sass": "^5.0.0",
    "popper.js": "^1.16.1",
    "sass-loader": "^10.1.0",
    "style-loader": "^2.0.0",
    "webpack": "^4.44.2",
    "webpack-assets-manifest": "^3.1.1",
    "webpack-cli": "^4.2.0",
    "webpack-manifest-plugin": "^3.0.0"
}

I have tried many other ways, changing the modules versions (like Webpack 5 etc.) but without success.
For another project I used Symfony 4 with Encore module and it worked. But with Slim 4 no success so far.

Thank you for sharing your experiences.

Webpack manifest file not exists.`

The file public/assets/manifest.json does not exists.

To compile all assets for development, run:

npm run build:dev

To compile and minify all assets for production, run:

npm run build

To watch files and recompile whenever they change, run:

npm run watch

Read more

Hi @odan, thank you for reply. But, as I wrote I am compiling assets by NPM and manifest.json is compiled into public/assets folder. Here is content of my manifest.json:

{
“vendor.css”: “assets/vendor.bundle.css”,
“vendor.js”: “assets/vendor.bundle.js”,
“vendor.eot”: “assets/webfonts/fa-solid-900.eot”,
“vendor.woff2”: “assets/webfonts/fa-solid-900.woff2”,
“vendor.woff”: “assets/webfonts/fa-solid-900.woff”,
“vendor.ttf”: “assets/webfonts/fa-solid-900.ttf”,
“vendor.svg”: “assets/webfonts/fa-solid-900.svg”,
“layout.css”: “assets/layout.bundle.css”,
“layout.js”: “assets/layout.bundle.js”,
“webfonts/fa-solid-900.svg”: “assets/webfonts/fa-solid-900.svg”,
“webfonts/fa-brands-400.svg”: “assets/webfonts/fa-brands-400.svg”,
“webfonts/fa-solid-900.eot”: “assets/webfonts/fa-solid-900.eot”,
“webfonts/fa-solid-900.ttf”: “assets/webfonts/fa-solid-900.ttf”,
“webfonts/fa-regular-400.svg”: “assets/webfonts/fa-regular-400.svg”,
“webfonts/fa-brands-400.eot”: “assets/webfonts/fa-brands-400.eot”,
“webfonts/fa-brands-400.ttf”: “assets/webfonts/fa-brands-400.ttf”,
“webfonts/fa-solid-900.woff”: “assets/webfonts/fa-solid-900.woff”,
“webfonts/fa-brands-400.woff”: “assets/webfonts/fa-brands-400.woff”,
“webfonts/fa-solid-900.woff2”: “assets/webfonts/fa-solid-900.woff2”,
“webfonts/fa-brands-400.woff2”: “assets/webfonts/fa-brands-400.woff2”,
“webfonts/fa-regular-400.eot”: “assets/webfonts/fa-regular-400.eot”,
“webfonts/fa-regular-400.ttf”: “assets/webfonts/fa-regular-400.ttf”,
“webfonts/fa-regular-400.woff”: “assets/webfonts/fa-regular-400.woff”,
“webfonts/fa-regular-400.woff2”: “assets/webfonts/fa-regular-400.woff2”
}
So I think that it’s not the problem of compiling itself. Here is my error full-stack trace:

#0 /home/dubak/projects/vendor/twig/twig/src/Parser.php(182): Fullpipe\TwigWebpackExtension\TokenParser\EntryTokenParserJs->parse()
#1 /home/dubak/projects/vendor/twig/twig/src/Parser.php(95): Twig\Parser->subparse()
#2 /home/dubak/projects/vendor/twig/twig/src/Environment.php(479): Twig\Parser->parse()
#3 /home/dubak/projects/vendor/twig/twig/src/Environment.php(507): Twig\Environment->parse()
#4 /home/dubak/projects/vendor/twig/twig/src/Environment.php(348): Twig\Environment->compileSource()
#5 /home/dubak/projects/vendor/twig/twig/src/Template.php(322): Twig\Environment->loadTemplate()
#6 /home/dubak/projects/vendor/twig/twig/src/Environment.php(358) : eval()'d code(43): Twig\Template->loadTemplate()
#7 /home/dubak/projects/vendor/twig/twig/src/Template.php(394): __TwigTemplate_9f237bec973ec2c56250181e573d9cdd64c8fa58950c0b843c2e3a9334b88ae0->doDisplay()
#8 /home/dubak/projects/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling()
#9 /home/dubak/projects/vendor/twig/twig/src/Template.php(379): Twig\Template->display()
#10 /home/dubak/projects/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render()
#11 /home/dubak/projects/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render()
#12 /home/dubak/projects/vendor/slim/twig-view/src/Twig.php(146): Twig\Environment->render()
#13 /home/dubak/projects/vendor/slim/twig-view/src/Twig.php(202): Slim\Views\Twig->fetch()
#14 /home/dubak/projects/src/Responder/Responder.php(68): Slim\Views\Twig->render()
#15 /home/dubak/projects/src/Action/HomeAction.php(39): App\Responder\Responder->render()
#16 /home/dubak/projects/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(43): App\Action\HomeAction->__invoke()
#17 /home/dubak/projects/vendor/slim/slim/Slim/Routing/Route.php(384): Slim\Handlers\Strategies\RequestResponse->__invoke()
#18 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\Routing\Route->handle()
#19 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\MiddlewareDispatcher->handle()
#20 /home/dubak/projects/vendor/slim/slim/Slim/Routing/Route.php(341): Slim\MiddlewareDispatcher->handle()
#21 /home/dubak/projects/vendor/slim/slim/Slim/Routing/RouteRunner.php(84): Slim\Routing\Route->run()
#22 /home/dubak/projects/vendor/slim/slim/Slim/Middleware/BodyParsingMiddleware.php(68): Slim\Routing\RouteRunner->handle()
#23 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\BodyParsingMiddleware->process()
#24 /home/dubak/projects/src/Middleware/UrlGeneratorMiddleware.php(43): class@anonymous->handle()
#25 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(209): App\Middleware\UrlGeneratorMiddleware->process()
#26 /home/dubak/projects/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(59): class@anonymous->handle()
#27 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process()
#28 /home/dubak/projects/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(107): class@anonymous->handle()
#29 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(209): Slim\Middleware\ErrorMiddleware->process()
#30 /home/dubak/projects/vendor/slim/twig-view/src/TwigMiddleware.php(125): class@anonymous->handle()
#31 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(209): Slim\Views\TwigMiddleware->process()
#32 /home/dubak/projects/vendor/selective/basepath/src/BasePathMiddleware.php(52): class@anonymous->handle()
#33 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(209): Selective\BasePath\BasePathMiddleware->process()
#34 /home/dubak/projects/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): class@anonymous->handle()
#35 /home/dubak/projects/vendor/slim/slim/Slim/App.php(215): Slim\MiddlewareDispatcher->handle()
#36 /home/dubak/projects/vendor/slim/slim/Slim/App.php(199): Slim\App->handle()
#37 /home/dubak/projects/public/index.php(3): Slim\App->run()
#38 {main}

So far I was able to bypass this error by adding the bundles directly to the twig layout:

<script src="./assets/vendor.bundle.js"></script>    
<script src="./assets/layout.bundle.js"></script>

but I really don’t like it to do it this way.
Please anybody, do you see something suspicious in the provided error stack trace?
Thank you.

Parser.php(182): Fullpipe\TwigWebpackExtension\TokenParser\EntryTokenParserJs->parse()

Now we have another error message. This looks like a token parser error.

Try to replace this:

{% webpack_entry_js ‘vendor’ %}

with this:

{% webpack_entry_js 'vendor' %}

@odan I’ve tried with single quotes and also double quotes:

{% webpack_entry_js ‘vendor’ %}

or

{% webpack_entry_js “vendor” %}

and I am getting same error:

/home/dubak/projects/vendor/twig/twig/src/Environment.php(358) : eval()'d code(43): Twig\Template->loadTemplate()
/home/dubak/projects/vendor/twig/twig/src/Template.php(394): __TwigTemplate_9f237bec973ec2c56250181e573d9cdd64c8fa58950c0b843c2e3a9334b88ae0->doDisplay()
/home/dubak/projects/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling()

Here is my composer.json file:

"require": {
        "php": "^7.4.0",
        "ext-json": "*",
        "ext-pdo": "*",
        "fullpipe/twig-webpack-extension": "^4.0",
        "php-di/php-di": "^6.0",
        "selective/basepath": "^2.0",
        "slim/psr7": "^1.2",
        "slim/slim": "^4.7",
        "slim/twig-view": "^3",
        "symfony/console": "^5.2",
        "symfony/http-foundation": "^5.2",
        "symfony/translation": "^5.2",
        "symfony/twig-bridge": "^5.2"
    },
    "require-dev": {
      "phpunit/phpunit": "^9.4",
      "friendsofphp/php-cs-fixer": "^2.16",
      "php-parallel-lint/php-parallel-lint": "^1.2",
      "php-parallel-lint/php-var-dump-check": "^0.5",
      "squizlabs/php_codesniffer": "^3.5"
    },
    "config": {
      "preferred-install": {
        "*": "dist"
      },
      "sort-packages": true,
      "platform": {
        "php": "7.4.0"
      },
      "secure-http": false
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }        
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Test\\": "tests/"
        }        
    },
    "replace": {
    },
    "repositories": [
    ],
    "scripts": {
    },
    "conflict": {
    },
    "extra": {
    }

and my system is running on:

~$ php --version
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
~$ composer --version
Composer 1.10.1 2020-03-13 20:34:27

Sorry, it is not clear (to me) what the error message is. Please show us the exact error message (not only the stack trace).

@odan I found the problem. Inside container.php I was retrieving twig settings by one line assignment:

$settings = $container->get('settings')['twig'];

which I found on your blog: https://odan.github.io/2019/09/21/slim4-compiling-assets-with-webpack.html

but after I changed it into:

$config = (array)$container->get('settings');
$settings = $config['twig'];

application started to work.