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

Does Flow support module path aliasing? #101

Closed
srcspider opened this issue Nov 22, 2014 · 10 comments
Closed

Does Flow support module path aliasing? #101

srcspider opened this issue Nov 22, 2014 · 10 comments
Labels

Comments

@srcspider
Copy link

From some of the presentations I've seen it seems flow has no issue with commonjs require syntax.

However, Is it possible to feed alias information into flow?

In grunt/gulp I prefer to go the extra mile and feed into the browserify/watchify/wathever task path alias information, so that instead of wriging require('../../../../../../lib/merge') and contextual variation thereof, I can just write require('lib/merge') (or require('subprogram/lib/merge') if the projects more complex) which is much easier to read, reason and grep/refactor. I also usually make directory names point to directory/path/name/index.node files (so I don't have to manually include every little piece of a component, ie. View, Model, etc).

If flow can only work with dumb require('../../../../lib/merge') calls that's quite the deal breaker.

@srcspider srcspider changed the title Does Flow support path aliasing? Does Flow support module path aliasing? Nov 22, 2014
@kompot
Copy link

kompot commented Jan 3, 2015

Tried to workaround this by creating a symlink in node_modules to an actual folder.

Flow's output has changed from
alias/innerFolder/componentName Required module not found
to
componentName Required module not found

but still does not work.

Seems like a deal breaker for me too.

@srcspider
Copy link
Author

@kompot can you test if it works with the hack of having your source tree folder called node_modules

ie.

/project
    node_modules/       # 3rd party
    src/
        node_modules/   # your stuff
            lib/        # your module
            system/     # your module

The hack here essentially allows you to reference lib, system (or combinations like lib/whatever) from anywhere in your own modules.

@kompot
Copy link

kompot commented Jan 3, 2015

@srcspider yep, it does work, thanks

But the next fail is on require('img/picture.jpg') which is handled by webpack.
I'd be happy to ignore that but could find a way to do that.

@srcspider
Copy link
Author

@kompot that is indeed bad

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@mroch
Copy link
Contributor

mroch commented Nov 30, 2015

I think you can probably do this now via the module.name_mapper config option. please reopen if it doesn't work!

@mroch mroch closed this as completed Nov 30, 2015
@cameron-martin
Copy link

I might be missing something, but I can't see how the name_mapper option would help with this. It seems that module.system.node.resolve_dirname could help though.

@gre
Copy link
Contributor

gre commented Aug 4, 2016

any chance to solve it without a symlink hack?
I can't make resolve_dirname to work .

@gre
Copy link
Contributor

gre commented Aug 4, 2016

nevermind, I found this https://github.com/cdebotton/react-universal/blob/master/.flowconfig

module.name_mapper='^common/(.*)$' -> '<PROJECT_ROOT>/../common/\1'

I also add to add ../common in [include] because it's beyond my project.

@draperunner
Copy link

gre's solution worked for me as well, but I had to escape the parentheses:

[include]
../common

[options]
module.name_mapper='^common/\(.*\)$' -> '<PROJECT_ROOT>/../common/\1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants