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

Does not work for path mapping starting with / #128

Closed
ashubham opened this issue Jul 6, 2020 · 8 comments · Fixed by #180
Closed

Does not work for path mapping starting with / #128

ashubham opened this issue Jul 6, 2020 · 8 comments · Fixed by #180

Comments

@ashubham
Copy link

ashubham commented Jul 6, 2020

I have tsconfig paths configured as:

"paths": {
      "/@utils/*": ["src/utils/*"],
      "/@services/*": ["src/services/*"],
      "/@contexts/*": ["src/contexts/*"],
      "/@translations/": ["src/services/system/localization/translations/index"]
},

These fail to resolve to the correct paths due to this line in code:
https://github.com/dividab/tsconfig-paths/blob/master/src/try-path.ts#L27

Do we need this check ?

@amonks
Copy link

amonks commented Jul 18, 2020

@ashubham I appreciate your work in finding this!

I'm trying to find a path-mapping solution that works with both parcel and tsconfig-paths, and parcel only likes path replacements when they start with /. Removing the line you pointed out met my needs!

@cspotcode
Copy link
Collaborator

@ashubham can you give me an example of some of the import statements you're writing to go along with this paths configuration?

@ashubham
Copy link
Author

I am trying to use https://github.com/vitejs/vite to build/bundle our application. Which needs custom path mappings to start with a / to differentiate from the npm namespace @namespace/package kind of dependencies.

So my imports look like:

import { getUtilFn } from '/@utils/layout';
import { useQuery } from '/@services/query';

@0x80
Copy link

0x80 commented Jul 28, 2020

@ashubham Just curious, and it's a matter of taste probably, but why do you start with /@utils and not just /utils? I'm using the latter, and I like the analogy of / as "root of your system" where it just points to the src folder in my repo.

As a workaround, until / is supported, I'm using ~/ which is like your user "home" folder so that's very similar :)

@surgicaI
Copy link

Now that typescript also allow the paths to start with a /, I believe the solution suggested by @ashubham is correct.
Should I create a pull request for the same

@benevbright
Copy link
Contributor

benevbright commented Oct 7, 2021

Removing that line did the trick.

My tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dest",
    "baseUrl": "./",
    "paths": {
      "/opt/*": ["./src/aws-layers/*"]
    }
  },
  "include": [
    "src/**/*"
  ],

import phrase

import { XXXX } from '/opt/utils';

Can we fix it?

@qmg-akara
Copy link

Hello, is there any update on this?

Our use case:
We have a Lambda mono-repo project. We import our lambda layer code as /opt/nodejs (this is where AWS Lambda puts our layer code) but as you know this is not available locally so we have paths: { "/opt/nodejs/*": "packages/layer/src/*" } in tsconfig file. But this bug causes linting issues so we temporarily disabled import/no-unresolved which is not great.

Thanks for the great work!

@qbasic16
Copy link

qbasic16 commented Dec 2, 2021

Hello, is there any update on this?

Our use case: We have a Lambda mono-repo project. We import our lambda layer code as /opt/nodejs (this is where AWS Lambda puts our layer code) but as you know this is not available locally so we have paths: { "/opt/nodejs/*": "packages/layer/src/*" } in tsconfig file. But this bug causes linting issues so we temporarily disabled import/no-unresolved which is not great.

Thanks for the great work!

I'm pretty sure a module import starting with an '/' failing to resolve is caused by this line: https://github.com/dividab/tsconfig-paths/blob/master/src/try-path.ts#L27

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

Successfully merging a pull request may close this issue.

8 participants