-
Notifications
You must be signed in to change notification settings - Fork 402
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 path aliases are not supported for .tsx files #1547
Comments
Why are you importing a |
The NestJS server I am working on must send emails in some use cases. |
I was able to find this is because of this line in our It might make more sense to be able to pass the file template to your renderer instead of trying to import it. Just my two cents |
The minimal reproduction StackBlitz project I had provided was actually too "minimal": I had I forked the project and modified it little bit so that it is a more realistic example:
This is the fork: https://stackblitz.com/edit/nestjs-typescript-starter-ylu6ro?file=src/main.ts If
But if the import is changed to an absolute path using the path alias, i.e.
Things I also want to note:
|
I think this might be actually an upstream issue with the |
I will check if I can reproduce the issue using |
I created a StackBlitz project using I then just dummy patched the line suggested by @jmcdo29 (in the NestJS StackBlitz project I posted before), and it resolves the issue! Before, when I used the unmodified "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@nestjs/core");
const app_module_1 = require("./app.module");
const ExampleComponent_1 = require("~/example/ExampleComponent"); // <-- here is the issue
async function bootstrap() {
console.log((0, ExampleComponent_1.renderComponent)());
const app = await core_1.NestFactory.create(app_module_1.AppModule);
await app.listen(3000);
}
bootstrap();
//# sourceMappingURL=main.js.map Note that the imports for both Once I "patch" the extension "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@nestjs/core");
const app_module_1 = require("./app.module");
const ExampleComponent_1 = require("./example/ExampleComponent"); // <-- fixed
async function bootstrap() {
console.log((0, ExampleComponent_1.renderComponent)());
const app = await core_1.NestFactory.create(app_module_1.AppModule);
await app.listen(3000);
}
bootstrap();
//# sourceMappingURL=main.js.map |
Would you like to create a PR to update this specific line? |
Yes I will create one 👍 |
Thank you @jmcdo29 and @kamilmysliwiec for helping resolving this fast, |
Is there an existing issue for this?
Current behavior
NestJS does support tsconfig.json path aliases for
.ts
files automatically, but it fails for.tsx
files.The reproduction project has the following changes applied to the StackBlitz template:
"jsx"
set to"preserve"
.src/example/ExampleComponent.tsx
which exports a constantExampleComponent
main.ts
ExampleComponent
ExampleComponent
(just to make sure the import is not eliminated)AppModule
to a path alias - that import works.@nestjs/*
dependencies inpackage.json
set to"8.3.1"
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-p48ucb?file=src%2Fmain.ts
Steps to reproduce
Just run
nest start
in the reproduction StackBlitz project.The following error is thrown:
Expected behavior
No error.
Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
8.3.1
Packages versions
8.3.1
Node.js version
14.19.0
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: