question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deep dependencies (auto resolve?)

See original GitHub issue

Hey there,

Firstly - this package is a godsend. Thanks for building it!

We’ve got fairly complex components that require deep dependencies, i.e. @material-ui/core/Paper where @material-ui/core is the package.

One solution is to manually type of each of those - though when you bring @material-ui/icons/${iconName} into the mix that can get quickly out of control with 1000+ components.

I noticed that createRequires takes a function - is there a way that I can automatically check which packages my remote component needs and pass in the corresponding package? i.e.

const mui = require('@material-ui/core');

const requires = createRequires({
   '@material-ui/core/Paper': mui.Paper
})

...

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
joelnetcommented, Dec 7, 2020

Is there a way within the component that you can map top level packages (i.e. @material-ui/core) to their sub module (i.e. @material-ui/core/Paper).

Could this be achieved by stripping the top level and using either dot notation or [] to go deeper into the package?

i.e. @material-ui/core/Paper/something/else -> requires[‘@material-ui/core’].Paper.something.else?

This is something I would have to play with. But the Manual Configuration section has some details on using a custom requires. The docs on this are light, but it should just be a function that takes a string and returns a module. You can do some custom processing inside that.

I’ll be improving the docs on that section shortly. But since it’s December, things are slow.

But I can say improvements in this area are on the near horizon 👍

1reaction
joelnetcommented, Dec 8, 2020

The requires should be created in the web application. I haven’t tested, but something like this:

const deps = {
  "@material-ui/core": require("@material-ui/core")
};

const requires = name => {
  const match = name.match(/@material-ui\/core\/(?<sub>.+)/, name);

  if (match) {
    return deps["@material-ui/core"][match.groups.sub];
  }

  return deps[name];
}

This should match an import of @material-ui/core/Paper to require("@material-ui/core").Paper

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to install npm peer dependencies automatically?
Older Answer. The automatic install of peer dependencies was explicitly removed with npm 3, as it cause more problems than it tried to...
Read more >
How to Automatically Eliminate Dependency Hell - ActiveState
Wrestling with Dependency Hell? Understand how the ActiveState Platform can help you automatically resolve dependency conflicts.
Read more >
Auto-installing peer dependencies in npm@7. #289 - GitHub
I have a question about auto-installing peer dependencies. In this PR @isaacs mentions that: ... Could not resolve dependency: npm ERR!
Read more >
Autodiscovery & Dependency Mapping | Resolve Systems
Resolve Insights automatically discovers complex, distributed applications and then maps dependencies to the underlying infrastructure components that support ...
Read more >
Introduction to the Dependency Mechanism - Apache Maven
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found