Skip to content
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

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

Closed
flavio-ever opened this issue Sep 8, 2023 · 8 comments
Assignees
Labels
Milestone

Comments

@flavio-ever
Copy link

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
Copy link
Author

flavio-ever commented Sep 8, 2023

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
  }
}

@kdy1 kdy1 added this to the Planned milestone Sep 9, 2023
@kdy1 kdy1 self-assigned this Sep 9, 2023
@tomer953
Copy link

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

@kdy1
Copy link
Member

kdy1 commented Sep 13, 2023

Can you try updaing @swc/core?

@kdy1
Copy link
Member

kdy1 commented Sep 13, 2023

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

@kdy1 kdy1 closed this as completed Sep 13, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.85 Sep 15, 2023
@Akaryatrh
Copy link

Akaryatrh commented Sep 22, 2023

@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:

  • open a new terminal
  • run npm start
  • see that compilation fails with Error: Cannot find module 'src/app.module'
  • modify "@swc/core": "^1.3.87" to "@swc/core": "1.3.78" (no caret) inside package.json
  • run npm i && npm start
  • see that it compiles successfully

@kdy1 kdy1 reopened this Sep 22, 2023
@kdy1 kdy1 closed this as completed Sep 22, 2023
@kdy1
Copy link
Member

kdy1 commented Sep 22, 2023

Please file a new issue instead

@Akaryatrh
Copy link

Done here #7990

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 23, 2023

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants