question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DllPlugin with CommonsChunkPlugin ReferenceError: vendor_dll is not defined

See original GitHub issue

Do you want to request a feature or report a bug? Bug

What is the current behavior? Uncaught ReferenceError: vendor_dll is not defined Possibly because output.library Template variables are not replaced If the current behavior is a bug, please provide the steps to reproduce. See below

What is the expected behavior? No reference errors when using the bundles in browser [name] replaced If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System. Version: webpack 3.4.1 Typescript

Currently I have a single DLL, its getting quite big, which means that “time to interactive” when I refresh pages is getting really long So I thought it may be possible to split the DLL into similar small chunks as my PROD build (pure CommonsChunkPlugin) Not sure if this is a supported scenario, it was eluded to here: https://github.com/webpack/webpack/issues/3783#issuecomment-270655641 https://github.com/webpack/webpack/issues/3871

The split I want is, one chunk for homepage, one chunk for standard pages and another chunk for “editing” pages This seems to work, the DLL compiles, the DLL can be used by DllReferencePlugin without webpack generation errors, the modules are split to the expected files with no duplicatations. However if I try to use it in the browser, I get a reference failure

var landingmodules = [
    "react",
    "react-dom",
    "react-router",
];

var mainmodules = landingmodules.concat([
    'redux',
    'redux-saga',
    "immutable",
]);

var maineditmodules = mainmodules.concat([
    'redux-form',
    "d3",
]);


const dllconfig: webpack.Configuration = mergesmart(basedllconfig, {
    entry: {
        landing: landingmodules,
        main: mainmodules,
        mainedit: maineditmodules
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            name: "vendor",
            filename: 'vendor.js',
            chunks: ["landing", "main", "mainedit"],
            minChunks: 3
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: "vendormain",
            filename: 'vendormain.js',
            chunks: ["main", "mainedit"],
            minChunks: 2
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: "vendormainedit",
            filename: 'vendormainedit.js',
            chunks: ["mainedit"],
            minChunks: 1
        }),
    ],
});

const basedllconfig: webpack.Configuration = {
    output: {
        path: path.resolve("./output/webpack-dll/dev"),
        filename: '[name].js', //file gets created as vendor.js correctly
        library: '[name]_dll', //[chunkhash] - gets replaced with "chunkhash", [hash] - throws an error
    },
    plugins: [
        new (webpack as any).DllPlugin({
            path: path.join("output", "/webpack-dll/dev", "[name]-manifest.json"), //file gets created as vendor.manifest.json correctly
            name: '[name]_dll'
            context: "."
        })
    ],
}

Looking at the generated bundles I see that the [name] was not replaced

landing.js

var landing_dll = webpackJsonp_name__dll([1],

main.js

var main_dll = webpackJsonp_name__dll([0]

mainedit.js

var mainedit_dll = webpackJsonp_name__dll([2]

vendor.js

// (function(modules) { // webpackBootstrap // // install a JSONP callback for chunk loading // var parentJsonpFunction = window[“webpackJsonp_name__dll”]; // window[“webpackJsonp_name__dll”] = function webpackJsonpCallback

vendormain.js

webpackJsonp_name__dll([3],

vendoredit.js

webpackJsonp_name__dll([5]

Looks like it could be a similar to these

https://github.com/webpack/webpack/issues/527 https://github.com/webpack/webpack/issues/2066

Tried the alternative syntax, however that didnt work either:

https://github.com/webpack/webpack/issues/221#issuecomment-39642737 https://github.com/webpack/webpack/issues/1189#issuecomment-259919350

    output: {
        path: path.resolve("./output/webpack-dll/dev"),
        filename: '[name].js',
        library: ["DLL", "[name]"],
    },

// (function(modules) { // webpackBootstrap // // install a JSONP callback for chunk loading // var parentJsonpFunction = window[“webpackJsonpDLL__name_”]; // window[“webpackJsonpDLL__name_”]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
sokracommented, Aug 23, 2017

Why is this not supported?

Nobody implemented it…


Just omit the CommonsChunkPlugins

0reactions
webpack-botcommented, Dec 5, 2018

This issue had no activity for at least half a year.

It’s subject to automatic issue closing if there is no activity in the next 15 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: vendor is not defined when using ...
This is because the DllPlugin expects to find the vendors inside a global scoped variable with e certain name (in your configuration, vendor...
Read more >
DllPlugin - webpack
The DllPlugin and DllReferencePlugin provide means to split bundles in a way that can drastically improve build time performance. The term "DLL" stands...
Read more >
Improve your webpack build with the DLL plugin
This tutorial shows you how to improve build times when working with webpack as a dependency for build tools using the DLL plugin....
Read more >
webpack优化问题,DLLPlugin 和DllReferencePlugin作用原理 ...
项目启动后,发现画面空白,浏览器F12查看问题,出现报错vendor_library is not defined。那就是说vendor.dll.js没引用到html文件入口中,但是自己 ...
Read more >
Javascript – Webpack vendor dll Reference Error - iTecNote
Building webpack vendor dll and getting. Uncaught ReferenceError: vendors_9a2b8ee29a9e8dcdc486b49a360b9763 is not defined.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found