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

create-react-app 2.0 - lerna - how to use absolute path imports within all packages #4942

Closed
kblooie opened this issue Aug 31, 2018 · 2 comments

Comments

@kblooie
Copy link

kblooie commented Aug 31, 2018

I'm using CRA 2.0's new lerna support #1333 #3741 and it's working great! However, I was wondering if there was a way to support absolute paths for all imports, not just the cross package imports.

Using the example site from #3741,
If cra-comps/comp1/comp1_internal.js was actually in
cra-comps/comp1/someotherfolder/comp1_internal.js

In comp1.js, is there a way to import it with:
import addInternal from 'someotherfolder/comp1_internal'
rather than:
'./someotherfolder/comp1_internal'

Given, this example is simple. However, a more complex folder structure makes the relative path imports a pain.

Are absolute paths imports within a package possible in this scenario?

@MikeSuiter
Copy link

@kblooie I just ran across this same problem and the best solution I could some up with is even though the import is in the same package, you have to treat it like it's in another package. For example cra-comps/comp1/comp1_internal.js currently has this import:

import addInternal from './comp1_internal';

To use an absolute import you need to do this:

import addInternal from 'comp1/comp1_internal';

So using your example you would need to do:

import addInternal from 'comp1/someotherfolder/comp1_internal';

I'm not a fan of it and would prefer not to have the comp1 if you're importing from the same package. Maybe this is possible but I haven't found a way to do it.

@kblooie
Copy link
Author

kblooie commented Sep 17, 2018

@MikeSuiter Thanks for the solution! I agree that it's not ideal, but it works for my needs.

@kblooie kblooie closed this as completed Sep 17, 2018
@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants