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.

DllReferencePlugin doesn't work with HotModuleReplacement when the webpack config is not the same directory of dll bundles

See original GitHub issue

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

What is the current behavior? So we have two project in two repos, one for compiling and one for app itself. The dll config is in app directory, and webpack config is in compile directory.

app/
-- node_modules
-- dll/
     --- vendor.dll.js
     ---vendor.manifest.js
-- app.js
-- dll.config.js (used to generate dll bundle)

compile/
-- node_modules
-- compile.js
-- webpack.config.js

It works fine for initial build. Dll work well. However when it comes to hot load, hot replacement plugin cannot find dll reference and generate correct hot-update.json. like this:

var e = new Error(\"Cannot find module \\\"dll-reference vendor_2fbac64ff6173d91e522\\\"\")

Hot load only works when I move the part of webpack config that use DllReferencePlugin back to app directories, like this

app/
-- node_modules
-- dll/
     ---vendor.dll.js
      ---vendor.manifest.js
-- app.js
-- dll.config.js
-- webpack.dllreference.config.js

compile/
-- node_modules
-- compile.js
-- webpack.config.js (import webpack.dllreference.config.js inside)

I checked the context I’ve pass into DllReferencePlugin for both way, it’s same because I’m always using process.cwd

If the current behavior is a bug, please provide the steps to reproduce.

my dll.config.js

import webpack from 'webpack';
import path from 'path';

const basePath = process.cwd();

export default {
  entry: {
    'vendor': [
       // list of vendor packages
    ],
  },
  output: {
    filename: '[name].dll.[chunkhash].js',
    path: path.join(basePath, 'dll/'),

    // The name of the global variable which the library's
    // require() function will be assigned to
    library: '[name]_[chunkhash]',
  },
  module: {
    // these loaders are needed for one of the vendor packages
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
        ],
      },
      {
        test: /\.(jpe?g|png|gif|eot|svg|ttf|woff|woff2)$/i,
        use: [
          'file-loader',
        ],
      },
    ],
  },
  plugins: [
    new webpack.DllPlugin({
      path: path.join(basePath, 'dll/[name].manifest.json'),
      name: '[name]_[chunkhash]',
    }),
  ],
};

What is the expected behavior?

Hot Module Replacement plugin should find dll reference when making hot-update.json

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.

node 6.9.5 webpack 3.4.1 mac os

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ldeavilacommented, Aug 28, 2017

@ethanyanjiali We are investigating a similar error Cannot find module "dll-reference dependencies".

Our current work around is to set cache: false Does setting cache: false resolve the error for you.

With cache: true we receive the error some times. @sokra If you are interested in viewing our error I can point you to a branch where the issue is easily reproducible.

0reactions
zhangsanshicommented, Sep 11, 2018

add all vender lib into entry in your webpack.config.js。

webpack.dll.config

import webpack from 'webpack';
import path from 'path';

const basePath = process.cwd();

export default {
  entry: {
    'vendor': [
       'a', 'b', 'c' // lib
    ],
  },
  output: {
    filename: '[name].dll.[chunkhash].js',
    path: path.join(basePath, 'dll/'),

    // The name of the global variable which the library's
    // require() function will be assigned to
    library: '[name]_[chunkhash]',
  },
  module: {
    // these loaders are needed for one of the vendor packages
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
        ],
      },
      {
        test: /\.(jpe?g|png|gif|eot|svg|ttf|woff|woff2)$/i,
        use: [
          'file-loader',
        ],
      },
    ],
  },
  plugins: [
    new webpack.DllPlugin({
      path: path.join(basePath, 'dll/[name].manifest.json'),
      name: '[name]_[chunkhash]',
    }),
  ],
};

webpack.config.js

import webpack from 'webpack';

export default {
  entry: {
    'app': [
       'a', 'b', 'c', 'src/index.js'  // add all lib into entry
    ],
  },
...others
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

DllPlugin - webpack
This plugin is used in a separate webpack configuration exclusively to create a dll-only-bundle. It creates a manifest.json file, which is used by...
Read more >
webpack dll configuration not working - Stack Overflow
Your bundle needs to include react. Marking react as externals excludes it from the bundle and makes it your responsibility to manually load...
Read more >
List of plugins - doc_webpack - Read the Docs
Output "dll" bundles. Dll bundles doesn't execute any of your module's code. They only include modules. A dll bundle exports a function which...
Read more >
Improve your webpack build with the DLL plugin
This tutorial shows you how to improve build times when working with ... webpack.vendor.config.js will be used for your unchanging bundles, ...
Read more >
CopyWebpackPlugin - webpack 3 documentation
Removes all directory references and only copies file names. ⚠️ If files have the same name, the result is non-deterministic. webpack.config.js module.
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