When using webpack-subresource-integrity@5.2.0-rc.1 in an ESM-based Webpack configuration, the build fails with:
[webpack-cli] Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/webpack-subresource-integrity/dist/mjs/plugin' imported from '.../node_modules/webpack-subresource-integrity/dist/mjs/index.js'
Steps to Reproduce
- Create a project with
"type": "module" in package.json.
- Install
webpack@5.97.1 and webpack-subresource-integrity@5.2.0-rc.1.
- Configure Webpack with an
.mjs file:
import { SubresourceIntegrityPlugin } from 'webpack-subresource-integrity';
export default {
plugins: [new SubresourceIntegrityPlugin({ hashFuncNames: ['sha384'] })]
};
- Run
webpack --mode production.
Expected Behavior
The build should succeed, resolving SubresourceIntegrityPlugin from the ESM entry (dist/mjs/index.js).
Actual Behavior
Fails with ERR_MODULE_NOT_FOUND because dist/mjs/index.js imports plugin, but dist/mjs/plugin.js (not .mjs) is present, causing Node.js ESM resolution to fail.
Environment
- Node.js: 22.13.1
- Webpack: 5.97.1
- webpack-subresource-integrity: 5.2.0-rc.1
- OS: Windows 11
Possible Cause
The ESM build in dist/mjs/ uses .js files (e.g., plugin.js), but Node.js expects .mjs or correct extension-less imports with "type": "module" in the package’s package.json. This mismatch breaks ESM resolution.
Suggested Fix
- Ensure
dist/mjs/ uses .mjs extensions (e.g., rename plugin.js to plugin.mjs) and update imports.
- Or, confirm
"type": "module" in the package’s package.json and adjust dist/mjs/index.js to use extension-less imports (e.g., import plugin from './plugin').
Workaround
Switching to CommonJS (dist/cjs/) by using .js config files resolves the issue.
Thanks for maintaining this plugin—happy to assist with a PR if needed!
When using
webpack-subresource-integrity@5.2.0-rc.1in an ESM-based Webpack configuration, the build fails with:Steps to Reproduce
"type": "module"inpackage.json.webpack@5.97.1andwebpack-subresource-integrity@5.2.0-rc.1..mjsfile:webpack --mode production.Expected Behavior
The build should succeed, resolving
SubresourceIntegrityPluginfrom the ESM entry (dist/mjs/index.js).Actual Behavior
Fails with
ERR_MODULE_NOT_FOUNDbecausedist/mjs/index.jsimportsplugin, butdist/mjs/plugin.js(not.mjs) is present, causing Node.js ESM resolution to fail.Environment
Possible Cause
The ESM build in
dist/mjs/uses.jsfiles (e.g.,plugin.js), but Node.js expects.mjsor correct extension-less imports with"type": "module"in the package’spackage.json. This mismatch breaks ESM resolution.Suggested Fix
dist/mjs/uses.mjsextensions (e.g., renameplugin.jstoplugin.mjs) and update imports."type": "module"in the package’spackage.jsonand adjustdist/mjs/index.jsto use extension-less imports (e.g.,import plugin from './plugin').Workaround
Switching to CommonJS (
dist/cjs/) by using.jsconfig files resolves the issue.Thanks for maintaining this plugin—happy to assist with a PR if needed!