microsoft / rushstack

Monorepo for tools developed by the Rush Stack community
https://rushstack.io/
Other
5.74k stars 587 forks source link

[set-webpack-public-path] The "hash" token does not match actual script hash #1107

Open sirianni opened 5 years ago

sirianni commented 5 years ago

I am using SetPublicPathPlugin with the following configuration:

  plugins: [
    new SetPublicPathPlugin({
      scriptName: {
        name: '[name]\-[hash]\.js',
        isTokenized: true,
      },
    }),
  ],

The hash being inserted into the generated webpack module cc6e266258d04761cb6d:

/******/    // Set the webpack public path
/******/    (function () {
/******/      var scripts = document.getElementsByTagName('script');
/******/      var regex = new RegExp('login-cc6e266258d04761cb6d.js', 'i');
/******/      var publicPath;

does not match the hash on the actual javacript bundle 4288b4fe1b87f8361a02:

Entrypoint login [big] = login-4288b4fe1b87f8361a02.js
octogonz commented 5 years ago

@iclanton FYI

iclanton commented 5 years ago

@sirianni - Can you share a repro?

halfnibble commented 5 years ago

If I'm reading this correctly, [hash] is going to be the chunk hash, but the generated webpack module may be using something different (like a content hash?).

sirianni commented 5 years ago

Here is what I'm using for webpack output:

  output: {
    path: `${__dirname}/dist`,
    publicPath: '/',
    filename: '[name]-[hash].js',
  },
halfnibble commented 5 years ago

I'm trying to reverse engineer what is happening here. It looks like you are doing everythin correct.

Can you tell me what version of Webpack you are using? Also, do you know what the Module Id is?

Just for kicks, I'm curious to see what the filename ends up as if you set your output settings to:

output: {
    path: `${__dirname}/dist`,
    publicPath: '/',
    filename: '[name]-[chunkhash].js',
},