waysact / webpack-subresource-integrity

Webpack plugin for enabling Subresource Integrity.
MIT License
357 stars 46 forks source link

webpack-subresource-integrity throws error when a processed tag has no attributes #147

Closed hchokshi closed 3 years ago

hchokshi commented 3 years ago

I have a project using webpack 5 and the latest versions of html-webpack-plugin and webpack-subresource-integrity. I also have a plugin that inlines scripts (e.g. webpack runtime chunk) into the generated HTML. This generates a <script> tag with no attributes, which causes webpack-subresource-integrity to throw when it checks the tag for an existing integrity attribute.

ERROR in   TypeError: Cannot convert undefined or null to object

  - hasOwnProperty

  - index.js:237 SubresourceIntegrityPlugin.processTag
    [client]/[webpack-subresource-integrity]/index.js:237:49

  - index.js:318
    [client]/[webpack-subresource-integrity]/index.js:318:48

  - Array.forEach

  - index.js:318
    [client]/[webpack-subresource-integrity]/index.js:318:26

  - new Promise

  - Hook.js:22 Hook.PROMISE_DELEGATE [as _promise]
    [client]/[html-webpack-plugin]/[tapable]/lib/Hook.js:22:14

  - index.js:311
    [client]/[html-webpack-plugin]/index.js:311:81

webpack 5.19.0 compiled with 1 error in 9396 ms
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [project-name]@0.1.0 build:prod: `webpack --mode production`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [project-name]@0.1.0 build:prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     E:\ProgramData\Cache\npm-cache\_logs\2021-01-31T02_37_05_041Z-debug.log
jscheid commented 3 years ago

Thanks, sounds like a regression from #122. Let me check first what happened to it.

jscheid commented 3 years ago

@hchokshi I need to understand this better so that we can write a test case for it. Could you create a repository with a minimal reproduction? What's the plugin you were mentioning?

hchokshi commented 3 years ago

Hey @jscheid, here's the bare minimum to repro - https://github.com/hchokshi/webpack-sri-inline-repro

jscheid commented 3 years ago

@hchokshi thanks for this. Aiming to release this in a new version later this week.

jscheid commented 3 years ago

Released in v5.0.0-alpha.2