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

[Bug]: Errors when using builtin webpack plugins #83

Open
1 task
titanous opened this issue Jan 5, 2023 · 1 comment
Open
1 task

[Bug]: Errors when using builtin webpack plugins #83

titanous opened this issue Jan 5, 2023 · 1 comment
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@titanous
Copy link

titanous commented Jan 5, 2023

What happened?

I'm trying to use a built-in webpack plugin, for example:

const { SourceMapDevToolPlugin } = require('webpack');

module.exports = {
    devtool: false,
    plugins: [new SourceMapDevToolPlugin({})],
}

and I get one of two errors depending on whether I include webpack as a dependency in the configuration:

[webpack-cli] Error: Cannot find module 'webpack'
[webpack-cli] TypeError: The 'compilation' argument must be an instance of Compilation

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazel 6.0.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

rules_webpack v0.7.0

How to reproduce

Full repro workspace here of every variant I tried: https://github.com/titanous/rules_webpack_require_error

Any other information?

No response

Fund our work

  • Sponsor our open source work by donating a bug bounty
@titanous titanous added the bug Something isn't working label Jan 5, 2023
@thesayyn
Copy link
Member

I know why this happens and is expected behavior; webpack in brought in via external repository which has its own npm_link_all_packages which links hermetically downloaded webpack next to webpack bin. by design this node_modules folder is not visible to other repositories which would be yours in this case.

you need to also link the hermetically downloaded webpack into your package to successfully resolve the same version of webpack.

load("@webpack//:npm_link_all_packages.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

webpack(
   data = [":node_modules/webpack"]
)

@thesayyn thesayyn added the documentation Improvements or additions to documentation label Jan 27, 2023
@gregmagolan gregmagolan moved this to 📋 Backlog in Open Source Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants