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.

Feature request: add support for babel-plugin-module-resolver

See original GitHub issue

Context

babel-plugin-module-resolver is an alternate way to alias module paths. The syntax is a bit simpler than Webpack’s alias option.

Expected Behavior

Would be awesome if dependency-cruiser could follow these aliases import paths.

Current Behavior

Currently, any import path aliased with babel-plugin-module-resolver is unresolvable.

Possible Solution

The module path mapping is pretty straight forward in the Babel config – it’s just alias name to relative path.

Considered alternatives

Could move our module aliases from our Babel config to our Webpack config

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
sverweijcommented, May 23, 2020

hi @atav32 & @tpucci thanks again for bringing this to my attention.

TL;DR The next version of dependency-cruiser will have babel support (including the plugin/ preset ecosystem) - also see the linked PR (#304 ☝️ ).

=> I’d love to hear any feed back on how it works for you. I’ve published with the beta tag on npm as dependency-cruiser@9.4.0-beta-1

rationale

@tpucci’s remark made me realise there’s use cases for having a babel plugin taking care of path aliasing. There might be more than these, but they’re already enough to warrant support in dependency-cruiser:

  • You might not have a bundler in your tool chain when you’re not developing for the web but for e.g. electron or atom (and react native, I guess?).
  • You might not be in a position to use TypeScript (yet or at all)

Next to that: dependency-cruiser uses acorn, and acorn only implements TC39 stage 4. If you’re using babel you likely do this because you want to use stuff from earlier stages, like export * as flakes from 'snowdash'. In order to enable you to use dependency-cruiser on that as well it’ll have to grow babel support too.

0reactions
sverweijcommented, Apr 17, 2021

@atav32 it should still work. If it doesn’t it’s a bug. I’ve tested it manually just now, and it seems to work fine still (both in 9.24.0 and 9.25.1).

=> Could you share your .dependency-cruiser.js?

I’ve split documentation of rules and options a while ago, which might explain why you couldn’t find it; it’s now here: babelConfig - use a babel configuration file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel-plugin-module-resolver | Yarn - Package Manager
This plugin allows you to add new "root" directories that contain your modules. It also allows you to setup a custom alias for...
Read more >
@fdao/babel-plugin-module-resolver - npm package | Snyk
A Babel plugin to add a new resolver for your modules when compiling your code using Babel. This plugin allows you to add...
Read more >
Options - Babel.js
would allow plugins and presets to decide that, since ES modules are supported, they will skip compilation of ES modules into CommonJS modules....
Read more >
Babel module resolver doesn't work as expected
Should be marked as the accepted solution. Adding aliases to babel (babelrc or babel.config) will only inform babel during transpiling that the ...
Read more >
Cannot Resolve Imports when using babel-resolver
I don't think we'd ever put efforts on adding special support for certain babel plugin... anyway, please feel free to file a request...
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