-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Completely disallow importing from outside of src/, packages/ or node_modules/ #834
Comments
Are you thinking this be implemented with an ESLint rule? |
The lack of Babel processing for importing outside of the |
Importing outside of I understand the difference is annoying, but you are just relying on unintentional behavior.
This is not really a supported way of using CRA. The supported way is to keep the project generated by CRA in the |
@gaearon, if I want to import version from package.json, what should I do? |
Maybe we could add an exception for this use case. @Timer thoughts? |
I believe supporting package.json is reasonable. |
I think some web apps would like to import the version number, or the dependencies used by the project to list somewhere. That's why |
What's the suggested solution for the following setup: I have two CRA-created apps. They each need a number of shared custom components that I also wrote. Do I need to (a) Host these component files in one app, and manually/scripted copy them over into the src folder of the other app every time I change them?
I understand that (b) is forbidden. Does that just leave me with (a)? |
What is currently the best solution to import components across CRA apps in monorepo? |
I was also wondering what do you do in cases with monorepos and multiple cra apps that want to import from a shared packages folder and have ts path mappings? Because it currently does not work. |
What about if I want do distinct my real CORE (application) than the other things? (source). |
We're also looking into this problem with our monorepo, as we're finishing our RN app, and moving into building the web, wanting to re-use as much as possible :/ |
I am having the same problem. I want to reuse components across my electron, web and RN projects. |
2.0 beta adds monorepo support, you can give it a try. |
i have the same problem. My create-react-app has client directory with src file and but when i try to import models which are outside the client file |
@dontito94 at this point, I recommend the prompt suggestion (ie move models/ into src/) |
@jasonszhao I am working on a project that allows you to do this. It has the concept of pages, which are basically multiple Your comments and bug reports are highly appreciated! |
Same issue here: some shared code between several projects in a sibling folder. We've implemented the symlink logic, it is working okay, but here are several downsides I see:
On the other hand, I have implemented an alias logic, this way:
then I can write:
and it is compiled in the bundle (checked it). This feels much cleaner for me, as this circumvents all the above points. There shall be some reason for not encouraging this, but I can't think of any for now. Any insight? Cheers |
@devxpy could you detail how you would do that? I can't see how. Thanks |
@augnustin I removed my comment because I don't correctly understand your directory structure, and it might not work for you. |
I do it automatically using .env file in react-pages. |
Hi, I have a project that I can't install with npm install but is in dependencies, I have tried babel-plugin-resolve-loader and
I know I have been using alias before without the need to eject (craco, react-app-rewired), why do I have this message? |
There shouldn’t be multiple conflicting ways to do the same thing. Currently we allow importing JS from anywhere but we don’t process it with Babel if it is outside
src
. This is slightly confusing and inconsistent. It also allows invalid/unsupported patterns like importing frompublic
folder (which exists for a completely different purpose), or frombuild
.After #741 is implemented and we have a first-class support for multiple top-level modules in a single repo, I think we should completely disallow importing JS or assets from anywhere else. Then we would have a clear picture of what each directory is for:
The text was updated successfully, but these errors were encountered: