Skip to content

If set type: module package.json, ts path-alias not replace, and can not resolve alias path module. #10267

Closed
@Innei

Description

@Innei

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Can't replace alias path if file in nested-folder, but in root dir such as /src replace correctly.

import { Module } from '@nestjs/common';
import { AppController } from '~/app.controller.js'; // right
import { AppService } from '~/app.service.js'; // right
import { TestModule } from '~/test/index.module.js'; // wrong

transform to:

import { Module } from '@nestjs/common';
import { AppController } from "./app.controller.js";
import { AppService } from "./app.service.js";
import { TestModule } from '~/test/index.module.js'; // not replaced!!!

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-pnhuer?file=dist/app.module.js&terminal=start

Steps to reproduce

npm start:dev


Error [ERR_MODULE_NOT_FOUND]: Cannot find package '~' imported from /home/projects/nestjs-typescript-starter-pnhuer/dist/app.module.js
    at InternalError.get (https://nestjs-typescript-starter-pnhuer.w.staticblitz.com/blitz.a1e315a41ec6498e2c2758b32fbf437db67b244b.js:6:292488)
    at process.emit (/home/projects/nestjs-typescript-starter-pnhuer/node_modules/source-map-support/source-map-support.js:508:52)
    at process.onGlobalUncaughtException [as _fatalException] (https://nestjs-typescript-starter-pnhuer.w.staticblitz.com/blitz.a1e315a41ec6498e2c2758b32fbf437db67b244b.js:6:251442)
    at Object.triggerUncaughtException (https://nestjs-typescript-starter-pnhuer.w.staticblitz.com/blitz.a1e315a41ec6498e2c2758b32fbf437db67b244b.js:15:356815)
    at i.loadESM (https://nestjs-typescript-starter-pnhuer.w.staticblitz.com/blitz.a1e315a41ec6498e2c2758b32fbf437db67b244b.js:6:246694)
    at handleMainPromise (https://nestjs-typescript-starter-pnhuer.w.staticblitz.com/blitz.a1e315a41ec6498e2c2758b32fbf437db67b244b.js:6:989050)

Expected behavior

replace tsc alias path.

Package

  • I don't know. Or some 3rd-party 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 (see below)

Other package

@nestjs/cli

NestJS version

9.0.11

Packages versions

 "@nestjs/cli": "9.1.2",

Node.js version

v16.14.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions