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

[Feature]: Custom package path resolver #1405

Closed
jaysoo opened this issue Jan 7, 2022 · 3 comments
Closed

[Feature]: Custom package path resolver #1405

jaysoo opened this issue Jan 7, 2022 · 3 comments

Comments

@jaysoo
Copy link

jaysoo commented Jan 7, 2022

What is the new or updated feature that you are suggesting?

It would be useful to have support for custom path mappings when importing packages. Currently, you could customize some paths in tsconfig or jsconfig, but there are limitations (see below).

Why should this feature be included?

In most build systems, users have the ability to customize package resolution. For example,

It would be useful for Remix to allow this type of configuration as well, and would give Nx the ability to support lightweight workspace libs for Remix apps.

Current solution and limitations

You can map paths in tsconfig.json or jsconfig.json, however there are some limitations.

  1. Remix currently treats modules not prefixed with . or ~ as external, so they are not bundled at compile time (https://github.com/remix-run/remix/blob/7d1dda3/packages/remix-dev/compiler.ts#L411-L413).
  2. In a monorepo setup you would configure the paths in a base config, not per-project. e.g. in tsconfig.base.json at the root of the monorepo. This conflicts with Remix's default paths as TS does merge paths.

Example

Given a monorepo as follows:

acme/
├── apps/
│   └── my-remix-app/
│       └── app/
│           ├── ...
│           └── routes/
│               └── index.tsx
└── libs/
    └── mylib/
        └── src/
            ├── ...
            └── index.ts

We want to map @acme/mylib to libs/mylib/src/index.ts so we can import it as such in our app.

// apps/my-remix-app/routes/index.tsx
import { something } from '@acme/mylib`';

Alternative solutions

  1. Allow custom esbuild plugins so we can do the mappings ourselves via onResolve callback ([Feature]: Allow custom esbuild-Plugins through remix.config.js #717).
  2. Use yarn/npm workspaces. This adds the requirement that libraries must be compiled, and is highlighted as an issue with the current Nx support for Remix. https://twitter.com/victorsavkin/status/1478769919676268552
@Knaackee
Copy link

This and I could try remix. Monorepo support is essential to me.

tyrauber added a commit to tyrauber/remix-react-native-web-starter that referenced this issue Feb 13, 2022
    
Instead of using pnpm, alias the module using tsconfig paths.
    
```
"paths": {
  "~react-native": ["./node_modules/react-native-web"],
  "~/*": ["./app/*"],
},
```
    
Remix currently only accepts paths with prefixes with ~ or ., as mentioned in this [this issues](remix-run/remix#1405), but this has the added benefit of allowing us to import react-native as well, or dependencies that have react-native as a peer dependency.
@machour
Copy link
Collaborator

machour commented Apr 12, 2022

@jaysoo #2412 landed and you can now define additional aliases in tsconfig.
Does that solve your issue?

@machour machour added the needs-response We need a response from the original author about this issue/PR label Apr 12, 2022
@github-actions
Copy link
Contributor

This issue has been automatically closed because we haven't received a response from the original author 🙈. This automation helps keep the issue tracker clean from issues that are unactionable. Please reach out if you have more information for us! 🙂

@MichaelDeBoey MichaelDeBoey removed the needs-response We need a response from the original author about this issue/PR label Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants