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

Add support for resolving modules with context within monorepos #95

Open
Rugvip opened this issue Jan 29, 2021 · 5 comments
Open

Add support for resolving modules with context within monorepos #95

Rugvip opened this issue Jan 29, 2021 · 5 comments

Comments

@Rugvip
Copy link

Rugvip commented Jan 29, 2021

External dependencies seem to always be resolved from the context of the entrypoint package rather than the package that imports the external dependencies.

For example consider

// packages/main/src/index.js
require('a')

// packages/a/src/index.js
require('express')

In this case we'll be resolving 'express' from the context of something like packages/main/dist/main.js, assuming main is the package where we set up the webpack build. If a happens to have its own version of express installed at packages/a/node_modules/express, that may end up not being used in favor of one installed in the main package or in the root node_modules.

A possible way to fix this is to pass the context to the importType option to allow a custom resolution logic to be set up, but it could also be something to build into this library either as an option or by default.

See the workaround here for more context: https://github.com/backstage/backstage/blob/d7f30a800db6e0dcee5de1a08b9ed88428dfe573/packages/cli/src/lib/bundler/config.ts#L312

@liady
Copy link
Owner

liady commented Apr 23, 2021

@Rugvip very good point. Will add this as an option (in order not to break current require behavior)

@uccmen
Copy link

uccmen commented Apr 30, 2021

@Rugvip , just curious, is your workaround intended to fix errors like this?

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

@Rugvip
Copy link
Author

Rugvip commented May 1, 2021

@uccmen No, although it's not impossible there are situations where the workaround would resolve that error just due to the dependency graph being changed.

@hiddenboox
Copy link

@rdsedmundo
Copy link

additionalModuleDirs doesn't fix this problem. The workaround provided by Rugvip does.

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

5 participants