You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
webpack-subresource-integrity does not play well with the [contenthash] path variable.
For instance with the following webpack.config.js:
var SRIPlugin = require("webpack-subresource-integrity")
module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "[name].[contenthash].js",
chunkFilename: "[name].[contenthash].js",
},
plugins: [
new SRIPlugin({
enabled: true, // set to false to stop breakage
hashFuncNames: [
"sha256",
"sha384",
],
}),
],
}
I get the following output:
$ webpack --config webpack.config.js
Unhandled rejection Error: Path variable [contenthash] not implemented in this context: [name].[contenthash].js
at fn (/Users/romeo/code/breaking-sri/node_modules/webpack/lib/TemplatedPathPlugin.js:43:11)
at fn (/Users/romeo/code/breaking-sri/node_modules/webpack/lib/TemplatedPathPlugin.js:31:16)
at String.replace (<anonymous>)
at replacePathVariables (/Users/romeo/code/breaking-sri/node_modules/webpack/lib/TemplatedPathPlugin.js:99:5)
at SyncWaterfallHook.eval [as call] (eval at create (/Users/romeo/code/breaking-sri/node_modules/tapable/lib/HookCodeFactory.js:17:12), <anonymous>:7:16)
at MainTemplate.getAssetPath (/Users/romeo/code/breaking-sri/node_modules/webpack/lib/MainTemplate.js:474:31)
at Object.getChunkFilename (/Users/romeo/code/breaking-sri/node_modules/webpack-subresource-integrity/util.js:130:50)
at Array.from.reverse.forEach.childChunk (/Users/romeo/code/breaking-sri/node_modules/webpack-subresource-integrity/index.js:191:23)
at Array.forEach (<anonymous>)
at SubresourceIntegrityPlugin.processChunk (/Users/romeo/code/breaking-sri/node_modules/webpack-subresource-integrity/index.js:185:48)
at forEachChunk (/Users/romeo/code/breaking-sri/node_modules/webpack-subresource-integrity/index.js:223:12)
at Array.forEach (<anonymous>)
at SubresourceIntegrityPlugin.afterOptimizeAssets (/Users/romeo/code/breaking-sri/node_modules/webpack-subresource-integrity/index.js:222:52)
at SyncHook.eval [as call] (eval at create (/Users/romeo/code/breaking-sri/node_modules/tapable/lib/HookCodeFactory.js:17:12), <anonymous>:7:1)
at SyncHook.lazyCompileHook [as _call] (/Users/romeo/code/breaking-sri/node_modules/tapable/lib/Hook.js:35:21)
at hooks.optimizeAssets.callAsync.err (/Users/romeo/code/breaking-sri/node_modules/webpack/lib/Compilation.js:981:38)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/romeo/code/breaking-sri/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/Users/romeo/code/breaking-sri/node_modules/tapable/lib/Hook.js:35:21)
at hooks.optimizeChunkAssets.callAsync.err (/Users/romeo/code/breaking-sri/node_modules/webpack/lib/Compilation.js:977:32)
at _err0 (eval at create (/Users/romeo/code/breaking-sri/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)
at /Users/romeo/code/breaking-sri/node_modules/uglifyjs-webpack-plugin/dist/index.js:334:11
at step (/Users/romeo/code/breaking-sri/node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:90:11)
at done (/Users/romeo/code/breaking-sri/node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:99:22)
at tryCatcher (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:638:18)
at Promise._resolveCallback (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:432:57)
at Promise._settlePromiseFromHandler (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:524:17)
at Promise._settlePromise (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:638:18)
at Promise._resolveCallback (/Users/romeo/code/breaking-sri/node_modules/bluebird/js/release/promise.js:432:57)
My limited understanding of the issue is that webpack-subresource-integrity tries to interpolate the filenames in getChunkFilename and that fails because the [contenthash] is not calculated yet at the point webpack-subresource-integrity runs (in the after-optimize-assets hook).
I suggest suggest doing one of two things:
Do not try to interpolate the asset names at all
Move to a later hook that does have the contenthash
webpack-subresource-integrity
does not play well with the[contenthash]
path variable.For instance with the following
webpack.config.js
:I get the following output:
My limited understanding of the issue is that
webpack-subresource-integrity
tries to interpolate the filenames ingetChunkFilename
and that fails because the[contenthash]
is not calculated yet at the pointwebpack-subresource-integrity
runs (in theafter-optimize-assets
hook).I suggest suggest doing one of two things:
contenthash
I've created a repo that reproduces this issue: https://github.com/romeovs/breaking-sri-contenthash
The text was updated successfully, but these errors were encountered: