Skip to content

Allow resolving imports from src #1043

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

Closed

Conversation

alphashuro
Copy link

Typing import x from '../../../../' has become quite cumbersome and error prone and a lot of people (including myself) have indicated a strong desire for a better solution, e.g. import x from 'components/x.js'.

The following addition allows resolving imports from src.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@EnoahNetzach
Copy link
Contributor

Wouldn't be better to add a "namespace" in order to avoid naming clash between packages and folders?

I mean something like (not necessarily with "_"):

import x from '_src_/components/x'

@alphashuro
Copy link
Author

considering that it will always check src folder first and node_modules afterwards, i don't think the namespace is necessary. if you name your folder the same as a node_module then you probably duplicating/replacing that module's functionality in which case you are better off importing the version in src, otherwise you can just name your dirs and files in src differently

@thien-do
Copy link
Contributor

In my opinion, I think this introduces a breaking change, right? For example, someone has a folder in src with the same name of one of their node modules. Then previously they was imported the node module, but now they will import the folder in their src, without changing anything in their code.

This is of course not a common use case, but theoretically it is possible, right?

@gaearon
Copy link
Contributor

gaearon commented Nov 16, 2016

Hi, thanks for the PR! Please search for "absolute imports" for many previous PRs that implemented the same features, and see the discussions explaining why we don't plan to take this particular implementation. Thank you!

@gaearon gaearon closed this Nov 16, 2016
@gaearon
Copy link
Contributor

gaearon commented Nov 16, 2016

Here is how we intend to solve this: #741. Would you like to explore this solution?

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants