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

Try to resolve from the context of the original request #5

Merged
merged 1 commit into from
Mar 27, 2020

Conversation

icatalina
Copy link
Contributor

What?

Use the context of the original request to try and validate some resource is available.

Why?

When trying to prove we can resolve a file, it is good to do it from the
original context of the file which is how webpack will try to resolve
it.

Some background:

In our company, we have a shared build tool which we install, said build tool contains a webpack.config.js file which will (hopefully) run this plugin.

One of the main reasons we have to use this plugin is to avoid installing core-js@3 in every app that consumes it. We need to redirect requests for core-js to the version installed alongside the build tool.

Our current node_modules looks something like this:

node_modules/
	core-js@2/ # Hoisted from other dependencies
	build-tool/
		webpack.config.js # It runs this plugin
		core-js@3/ # The one we will like to use

Using require.resolve(originalRequest) will resolve that request from the context of build-tool which does contain core-js@3 and will work. But most of the request come from the code babel will inject in our app. Which means they will actually be required from the context of the main app hence trying to use core-js@2. Without the { paths: [] } options, require.resolve will succeed while the actual webpack require will fail, this PR solves that issue.

Thanks :)

When trying to prove the resolve works, it is good to do it from the
original context of the file which is how webpack will try to resolve
it.
@icatalina
Copy link
Contributor Author

Hi @ndelangen! could you have a look at this?

@ndelangen ndelangen merged commit 3c7e6f3 into ndelangen:master Mar 27, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants