swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.96k stars 1.21k forks source link

Build is breaking after upgrade SWC CORE 1.3.78 to 1.3.79 in NestJs projects. #7930

Closed flavio-ever closed 1 year ago

flavio-ever commented 1 year ago

Describe the bug

Hello, I'm currently experimenting with NestJs projects with SWC as per the documentation: https://docs.nestjs.com/recipes/swc

Everything was going fine until I decided to create a new project with the latest patch, but I'm getting:

>  SWC  Running...
Successfully compiled: 5 files with swc (25.55ms)
Watching for file changes.
Error: Cannot find module 'node_modules/@nestjs/core/index.js'
Require stack:
- /home/flavioever/PESSOAL/project/procjet-backend/dist/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Function.Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/home/flavioever/PESSOAL/project/procjet-backend/dist/main.js:5:15)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

I analyzed version 1.3.79 up to 1.3.83 and I noticed that the dist/main.js file is pointing to:

const _appmodule = require("src/app.module");

And not as it should in 1.3.78

const _appmodule = require("./app.module");

The project is clean, just the cli version adding the swc already triggers the errors: @swc/cli": "0.1.62", "@swc/core": "1.3.78", I'm testing the project on WSL2. So basically something happened in patch 1.3.79 that broke file paths.

Input code

No response

Config

// https://swc.rs/docs/configuration/swcrc
// https://docs.nestjs.com/recipes/swc
{
  "$schema": "https://json.schemastore.org/swcrc",
  "sourceMaps": true,
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "dynamicImport": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "baseUrl": "./"
  },
  "minify": false
}

Playground link

No response

SWC Info output

`

SWC Running... Successfully compiled: 5 files with swc (25.55ms) Watching for file changes. Error: Cannot find module 'node_modules/@nestjs/core/index.js' Require stack:

  • /home/flavioever/PESSOAL/project/procjet-backend/dist/main.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1075:15) at Function.Module._load (node:internal/modules/cjs/loader:920:27) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at Object. (/home/flavioever/PESSOAL/project/procjet-backend/dist/main.js:5:15) at Module._compile (node:internal/modules/cjs/loader:1254:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Function.Module._load (node:internal/modules/cjs/loader:958:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) `

Expected behavior

⠋  TSC  Initializing type checker...[Nest] 28261  - 09/07/2023, 11:20:10 PM     LOG [NestFactory] Starting Nest application...
[Nest] 28261  - 09/07/2023, 11:20:10 PM     LOG [InstanceLoader] AppModule dependencies initialized +7ms
[Nest] 28261  - 09/07/2023, 11:20:10 PM     LOG [RoutesResolver] AppController {/}: +7ms
[Nest] 28261  - 09/07/2023, 11:20:10 PM     LOG [RouterExplorer] Mapped {/, GET} route +2ms
[Nest] 28261  - 09/07/2023, 11:20:10 PM     LOG [NestApplication] Nest application successfully started +2ms
✔  TSC  Initializing type checker...

Actual behavior

No response

Version

1.3.83

Additional context

No response

flavio-ever commented 1 year ago

The funny thing about all this is that with the use of "paths" in "tsconfig.json" the errors stop, is it something new and undocumented? But unfortunately I'm not used to using "aliases" in my projects and since the update I feel obliged to work around the problem.

Full:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    },
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}
tomer953 commented 1 year ago

same here, we downgraded to 1.3.78 and everything is working again.

kdy1 commented 1 year ago

Can you try updaing @swc/core?

kdy1 commented 1 year ago

Closing as there's no repro, and there are many fixes related to es/module in the recent changelog.

https://github.com/swc-project/swc/blob/858a4f4a22d9c815b16a2c87f650f7dceeb5c7a6/CHANGELOG.md#1384---2023-09-11

Akaryatrh commented 1 year ago

@kdy1 Can you please reopen it? Here's a reproducible example on CodeSandBox with latest swc core version published (1.3.87): https://codesandbox.io/p/sandbox/dawn-hill-9858zs?file=/package.json:34,5-34,28

Steps to reproduce:

kdy1 commented 1 year ago

Please file a new issue instead

Akaryatrh commented 1 year ago

Done here https://github.com/swc-project/swc/issues/7990

swc-bot commented 11 months ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.