Using Path Aliases

WunderGraph currently doesn't support tsconfig path aliases out of the box, but there is a simple workaround using package.json subpath imports.

Subpath imports allow you to configure private mappings that only apply to import specificiers from within the package itself. Entries in the "imports" field must always start with # to ensure they are disambiguated from external package specifiers.

Configuration

To create an alias to the generated folder of WunderGraph, add the following to package.json.

1
2
3
4
5
6
// package.json
{
"imports": {
"#/generated/*": "./.wundergraph/generated/*"
}
}

Then to make sure the TypeScript compiler also supports this path, it needs to be added to paths in tsconfig.json. Make sure you also configure the baseUrl.

1
2
3
4
5
6
7
8
9
10
// tsconfig.json
{
"compilerOptions": {
// ... truncated
"baseUrl": ".",
"paths": {
"#/generated/*": [".wundergraph/generated/*"]
}
}
}

Et voila, now you can import the generated code from this path alias.

1
import { createClient } from '#/generated/client';

If you are using a monorepo setup, you need to make sure to configure these paths in every package that require them.

More info

Was this article helpful to you?
Provide feedback

Edit this page