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

TypeScript paths is ignored #121

Closed
TimMensch opened this issue Mar 17, 2020 · 6 comments
Closed

TypeScript paths is ignored #121

TimMensch opened this issue Mar 17, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@TimMensch
Copy link

In my tsconfig I use the following pattern:

{
        "paths": {
            /* The ~ option for easier imports: "~some/path" */
            "~*": ["./*"]
        },
}

This means I can specify imports as follows:

import { Layout } from "~components/Layout";

This pattern eliminates the annoying "../.../components/Layout" style relative paths that need to be divined based on what folder you're currently in, or adjusted as you move files or copy code around. VS Code also supports this for auto-imports. It's relatively standard, and is also supported by parcel.

Zero, unfortunately, sees "~components" as a package and tries (and fails) to import it. A simple fix would be to grab the paths entry from tsconfig.json and ignore any imports that match any of the path globs.

@asadm asadm added the bug Something isn't working label Mar 20, 2020
@asadm
Copy link
Contributor

asadm commented Mar 20, 2020

I agree about this particular shorthand pattern ie. ~ for project root. The underlying parcel also supports it. I would count this as a bug in zero, I will look into this soon.

About parsing tsconfig.json.paths and ignoring those paths, I think it would be a good enhancement. If we just address the common patterns (like the ~ usage) this might be just unnecessary effort.

@TimMensch
Copy link
Author

It's true that ~ usage will hit the 99th percentile of usefulness. If that's a lot easier, then I'd say it's fine. Was thinking that just checking against the globs would work, but I could be wrong.

@asadm
Copy link
Contributor

asadm commented Mar 20, 2020

It looks like there is an underlying parcel bug too. I guess I will have to patch that and see if that works. I will try to get this fix up this weekend.

@asadm
Copy link
Contributor

asadm commented Mar 22, 2020

@TimMensch can you try the installing the latest version. #122 fixes the root imports using ‘~’

@TimMensch
Copy link
Author

Thanks for the fast fix! Seems to work great. Closing.

I was testing zero for my site, and it's wonderful for what it does, but I ended up running into a different limitation (or at least a problem I couldn't solve) that made me try Next.js instead -- and now I have a working Next.js environment. I can't remember what the limitation was, though it may have been that I couldn't figure out how to get it to spit out valid AMP HTML? Next.js has native AMP support. There are specific things that AMP sites need, like a <style amp-custom> block, that React and similar don't support well, and I wanted to also use MDX in the same site for content.

The current project is more important to finish than to use the perfect platform. I'll absolutely consider zero for my next project, though.

Thanks again!

@asadm
Copy link
Contributor

asadm commented Mar 24, 2020

I understand. AMP can be looked into in the future and should be easy to add.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants