nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.95k stars 389 forks source link

broken path in build output #2534

Open tigawanna opened 6 months ago

tigawanna commented 6 months ago

Is there an existing issue for this?

Current behavior

Hey guys am getting this error when trying to import a module into another

// posts module
@Module({
  controllers: [PostsController],
  providers: [PostsService],
  imports: [ColorsModule],
})
export class PostsModule {}

// colors module
@Module({
  controllers: [ColorsController],
  providers: [ColorsService],
  exports: [ColorsService],
})
export class ColorsModule {}

// dist posts mudole.js output

"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "PostsModule", {
    enumerable: true,
    get: function() {
        return PostsModule;
    }
});
const _common = require("@nestjs/common");
const _postsservice = require("./posts.service");
const _postscontroller = require("./posts.controller");
const _colorsmodule = require("/?/C:/Users/denni/Desktop/code/node/nestjs/nestjs-typeorm/src/colors/colors.module");
function _ts_decorate(decorators, target, key, desc) {
....

manually changing

const _colorsmodule = require("/?/C:/Users/denni/Desktop/code/node/nestjs/nestjs-typeorm/src/colors/colors.module")
//to
const _colorsmodule = require("../colors/colors.module")

fixes ths issue , what am i doing wrong?

Minimum reproduction code

https://github.com/tigawanna/nestjs_typeorm/tree/minimal-reproduction

Steps to reproduce

  1. npm ci 2. npm run start:swc

Expected behavior

start up server with no errors

Package

Other package

10

NestJS version

No response

Packages versions

  "dependencies": {
    "@nestjs/common": "^10.0.0",
    "@nestjs/config": "^3.2.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/jwt": "^10.2.0",
    "@nestjs/passport": "^10.0.3",
    "@nestjs/platform-express": "^10.0.0",
    "@nestjs/swagger": "^7.3.0",
    "@nestjs/typeorm": "^10.0.2",
    "@types/bcrypt": "^5.0.2",
    "bcrypt": "^5.1.1",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "passport": "^0.7.0",
    "passport-local": "^1.0.0",
    "pg": "^8.11.3",
    "reflect-metadata": "^0.2.0",
    "rxjs": "^7.8.1",
    "sqlite3": "^5.1.7",
    "typeorm": "^0.3.20"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/mapped-types": "^2.0.5",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@swc/cli": "^0.3.9",
    "@swc/core": "^1.4.2",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.1",
    "@types/passport-local": "^1.0.38",
    "@types/supertest": "^6.0.0",
    "@typescript-eslint/eslint-plugin": "^6.0.0",
    "@typescript-eslint/parser": "^6.0.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "jest": "^29.5.0",
    "prettier": "^3.0.0",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3",
    "unplugin-swc": "^1.4.4",
    "vitest": "^1.3.1"
  },

Node.js version

20

In which operating systems have you tested?

Other

with npm run start:dev

image

with npm run start:swc

image

micalevisk commented 6 months ago

I didn't manage to reproduce your issue on my Ubuntu. Try it out:

git clone git@github.com:tigawanna/nestjs_typeorm.git -b minimal-reproduction
cd nestjs_typeorm/
npm install
npm run start:swc

image

tigawanna commented 6 months ago

works in wsl , looks like a windows issue

Linux output in dtst/posts/post.module,js

const _common = require("@nestjs/common");
const _postsservice = require("./posts.service");
const _postscontroller = require("./posts.controller");
const _colorsmodule = require("../colors/colors.module");

vs Windows output in dtst/posts/post.module,js

const _common = require("@nestjs/common");
const _postsservice = require("./posts.service");
const _postscontroller = require("./posts.controller");
const _colorsmodule = require("/?/C:/Users/denni/Desktop/code/node/nestjs/minimal/src/colors/colors.module");

manually correcting the path will fix the issue and it only appears when importing external modules (colors into posts)

micalevisk commented 6 months ago

@tigawanna what if you don't use swc? perhaps that's something we cannot fix on our side

tigawanna commented 6 months ago

ts-node without swc works fine it's just slow but i get there's not much you can do about an SWC issue