Skip to content

webpack-subresource-integrity v5.2 incompatibility #972

@ralitsabo

Description

@ralitsabo

Expected behavior:

We should be able to enable integrity support with webpack-subresource-integrity v5.1/v5.2.

Actual behavior:

When I am trying to enable the integrity for PROD, I have the following error on compile:

> bin/shakapacker

[Shakapacker] Looking for Webpack config in: /PROJECT_PATH/config/webpack/webpack.config.ts, /PROJECT_PATH/config/webpack/webpack.config.js
[Shakapacker] Found Webpack config: /PROJECT_PATH/config/webpack/webpack.config.js
[Shakapacker] Preparing environment for assets bundler execution...
[Shakapacker] Base command: /PROJECT_PATH/node_modules/.bin/webpack
[Shakapacker] Adding config file: /PROJECT_PATH/config/webpack/webpack.config.js
[Shakapacker] Final command: /PROJECT_PATH/node_modules/.bin/webpack --config /PROJECT_PATH/config/webpack/webpack.config.js
[Shakapacker] Working directory: /PROJECT_PATH
[webpack-cli] Failed to load '/PROJECT_PATH/config/webpack/webpack.config.js' config
[webpack-cli] TypeError: SubresourceIntegrityPlugin is not a constructor
    at getPlugins (/PROJECT_PATH/node_modules/shakapacker/package/plugins/webpack.js:47:22)
    at Object.<anonymous> (/PROJECT_PATH/node_modules/shakapacker/package/environments/base.js:89:14)
    at Module._compile (node:internal/modules/cjs/loader:1761:14)
    at Object..js (node:internal/modules/cjs/loader:1893:10)
    at Module.load (node:internal/modules/cjs/loader:1481:32)
    at Module._load (node:internal/modules/cjs/loader:1300:12)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
    at Module.require (node:internal/modules/cjs/loader:1504:12)
    at require (node:internal/modules/helpers:152:16)
[Shakapacker] Completed webpack build in 2.5s (2.5s)

Looks like webpack-subresource-integrity v5.1.0 exports the class as a named export so requireOrError returns { SubresourceIntegrityPlugin: [class] }, not the class itself. Shakapacker then tries `new { SubresourceIntegrityPlugin: [class] }(...) which fails with "not a constructor".

Temp. fix: ⚠️ When I downgrade to "webpack-subresource-integrity": "^1.5.2" - all is good.

Additional information

I saw you already have similar fix for the WebpackAssetsManifest here.

Small, reproducible repo:

N/A

Setup environment:

  • Ruby version: 3.3.6
  • Rails version: 6.1.7.6
  • Shakapacker version: 9.5
  • webpack-subresource-integrity - 5.1 | 5.2
  • Node: v24.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions