Skip to content

Cannot import into webpack.mjs #97

@FrozenKiwi

Description

@FrozenKiwi

When importing into an esm module:

(node:29176) UnhandledPromiseRejectionWarning: ReferenceError: require is not defined in ES module scope, you can use import instead
    at file:///<...>/node_modules/error-overlay-webpack-plugin/dist/index.mjs:1:32

The index.mjs file is implemented as:

const errorOverlayMiddleware = require("react-dev-utils/errorOverlayMiddleware");
const chunkPathBasic = require.resolve("./entries/basic.mjs");
const chunkPathDevServer = require.resolve("./entries/devserver.mjs");

This seems like an invalid import. I don't think it is related to #93, as this appears to be updating .cjs files, rather than .mjs.

For my workaround, in my webpack I have created a shim error-overlay-shim.js file that to force the import of eowp as cjs

//
// The MJS exports of error-overlay use require, and aren't valid
// in a module.  Shimming with a .js file forces us to import cjs version
const ErrorOverlayPlugin = require('error-overlay-webpack-plugin')

module.exports = ErrorOverlayPlugin;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions