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

Support TypeScript 4.1 #59

Closed
talohana opened this issue Dec 12, 2020 · 10 comments · Fixed by #105
Closed

Support TypeScript 4.1 #59

talohana opened this issue Dec 12, 2020 · 10 comments · Fixed by #105

Comments

@talohana
Copy link

talohana commented Dec 12, 2020

TypeScript 4.1 adds an option to use path mapping without specifying baseUrl, more about it in TypeScript 4.1 Release Notes

My project is using TypeScript 4.1.2, trying to remove the baseUrl I get the following error

Failed to load tsconfig.json: Missing baseUrl in compilerOptions
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin

Would like to submit a PR with a little help :)

@jakebailey
Copy link

See also: dividab/tsconfig-paths#143, #32 (comment)

@jakebailey
Copy link

Since 4.1, I've worked around this with secondary configs that extend and add a baseUrl; after hitting more bugs like #60, I've found that it's easier to drop the plugin in favor of a little code that transforms the paths config into webpack resolve aliases; the output is identical to the tsconfig-paths plugin (when it's working).

@7iomka
Copy link

7iomka commented Dec 30, 2021

@jakebailey

Hi, share please your solution / example repo?
I have similar issues

@jakebailey
Copy link

Sure, the function I wrote to generate aliases is here: https://github.com/microsoft/pyright/blob/169c6089b9914870c43622743c75844657cd9d70/build/lib/webpack.js#L90

resolve.alias gets set to the return value of this function.

As far as I can tell, this is all you need to support tsconfig paths. It verifies enough to make the file ts-check (hence the asserts), but otherwise is all that's really needed to make paths work, no plugin needed.

@7iomka
Copy link

7iomka commented Dec 30, 2021

https://github.com/microsoft/pyright/blob/169c6089b9914870c43622743c75844657cd9d70/build/lib/webpack.js#L90

resolve: {
            extensions: ['.ts', '.js'],
            alias: tsconfigResolveAliases('tsconfig.json'),
        },

That is enough?

@jakebailey
Copy link

Correct.

@7iomka
Copy link

7iomka commented Dec 30, 2021

Correct.

With storybook it is correct usage?

  webpackFinal: async (config) => {
    // resolve problem with typescript aliases
    config.resolve.alias = {
      ...config.resolve?.alias,
      ...tsconfigResolveAliases('../tsconfig.json'),
    };
  ....
}

@jakebailey
Copy link

I have no idea what storybook is, but I don't see why not. Can't hurt to try.

@7iomka
Copy link

7iomka commented Dec 30, 2021

I have no idea what storybook is, but I don't see why not. Can't hurt to try.

I have that config

{
  "extends": "./tsconfig/nextjs.json",
  "include": ["."],
  "exclude": ["dist", "build", "node_modules"]
}

With JSONC you parse content of file and compilerOptions required inside.
Any workaround for that kind of configs?
filepath on the field extends may have similar extends (That is how monorepo configs structured)

@jakebailey
Copy link

Last I looked, paths is not a config that is carried over from the extended config, so if your project doesn't copy/paste paths around, they aren't working correctly in the first place, and my snippet is still doing the right thing by not following extended paths. The project that uses my little helper (pyright and Pylance) are forced to duplicate them in every tsconfig.

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.

3 participants