Skip to content
Advertisement

Webpack successfully builds, but JavaScript doesn’t execute runtime

I have migrated Webpack v4 to v5, made changes relative to documentation and deprecation messages from CLI, and got successful build, though during the application testing I noticed that JavaScript doesn’t run and there are no errors. I am getting plain html rendered by SSR.

Have no clue why it doesn’t work, because it’s silent, maybe misconfiguration issue.

Here is my webpack configuration:

JavaScript

Here the dev dependencies that I use

JavaScript

EDIT

I am suing assets-webpack-plugin as you can see, which gives me JSON of entrypoints and chunks. I am manually inserting the bundle.[contenthash].js and vendor.[contenthash].js to my index.html which loads successfully.

But in source code of compiled bundles, I can see that bundle isn’t runtime executable function, but webpack module.

I have tried runtime property on vendor entrypoint, because main bundle point is depended on vendor packages, even though it gave me executable function it doesn’t execute my main bundle code.

Advertisement

Answer

After more investigation I found, that besides entry bundles and runtime file, webpack creates few more files needed for initial execution.

So for making custom html file or using any other preprocessor file we need to use either html-webpack-plugin to generate html file based on optionally provided template or webpack-manifest-plugin to get the list of the needed files in json file.

JavaScript

Here with available filter option we process files. filter function provides FileDescriptor object as an input for processing which containes isInitial, isChunk and few more fields which you can find in documentation

As you already guessed the files marked as isInitial needed for running your application. Also you can generate custom manifest file using this plugin. For example I have a file where have separated initial css and js bundles.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement