Skip to content

ERR_MODULE_NOT_FOUND with ESM in 5.2.0-rc.1 - Missing dist/mjs/plugin #236

Description

@NimaBakhtiyari

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

  1. Create a project with "type": "module" in package.json.
  2. Install webpack@5.97.1 and webpack-subresource-integrity@5.2.0-rc.1.
  3. Configure Webpack with an .mjs file:
    import { SubresourceIntegrityPlugin } from 'webpack-subresource-integrity';
    export default {
      plugins: [new SubresourceIntegrityPlugin({ hashFuncNames: ['sha384'] })]
    };
  4. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions