Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "cannot find module 'xxx'" when bundled with webpack #70

Open
madtisa opened this issue Jan 23, 2024 · 2 comments
Open

Error "cannot find module 'xxx'" when bundled with webpack #70

madtisa opened this issue Jan 23, 2024 · 2 comments

Comments

@madtisa
Copy link

madtisa commented Jan 23, 2024

Description

I was unable to configure webpack the way that __non_webpack__require__ is defined, so using bundle always results in error: "Cannot find module". Is it a bug or am I missing something (and if so, how can I make it work)?

Bundled real require looks like this (all requires are replaced to __webpack__require__s, but __non_webpack__require__ is ignored and is always undefined):

function realRequire(modulePath) {
    if (typeof __non_webpack__require__ === 'function') {
        return __non_webpack__require__(modulePath)
    }

    return __webpack_require__("./node_modules/real-require/src sync recursive")(modulePath)
}

Demos that displays this behavior

@madtisa
Copy link
Author

madtisa commented Jan 23, 2024

As a workaround you can forcefully define __non_webpack__require__ to globalThis.require in webpack.config.js:

const {DefinePlugin} = require('webpack');
module.exports = {
    ...
    plugins: [
        new DefinePlugin({
            __non_webpack__require__: 'globalThis.require',
        }),
    ]
}

@mcollina
Copy link
Member

mcollina commented Feb 1, 2024

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants