-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
baseUrl
not working in Nest 10 with swc
#7603
Comments
I think this is a duplicate |
@kdy1 can you link the original issue in this case? I can't find it |
I see you put the bug in milestone v1.3.68 @kdy1 |
It's not fixed. It's duplicate |
I told you. |
Okay, that's a misinterpretation on my part, sorry. I thought the bug was fixed in version 1.3.68, hence my feedback! 😅 |
@KirianCaumes I don't find the duplicate neither |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as spam.
This comment was marked as spam.
@KirianCaumes have you managed to make it work? |
@gabrielcipriano In this NestJS 10 boilerplate the SWC compiler works, so I'd suggest to look what they did there. Only on Windows it fails to serve due to a bug in SWC: nestjs/nest#12214 |
@kdy1 I'm not entirely sure as the errors or setups vary slightly. It basically is this (the rest of the thread should give the necessary context): nestjs/nest#11891 (comment) Reading the thread a bit more closely, I do notice this comment which is pretty much the same error/conclusion as the issue you refer to: nestjs/nest#11891 (comment). It would be interesting to see if the resulting compilation is different on MacOS or Unix. I could try this if you want me to 👍 |
@kdy1 I did a bit more research on my Windows PC. Switching to the non-SWC compiler I got a relative path that allowed my app to work. Going back to SWC I got an absolute path which did not work. Manually making the path relative by changing the compiled JS file (just like it was in the non-SWC dist) and my app worked again. So the tl:dr, if the path can be become relative on Windows at least some of the issues will be resolved, maybe all of them as think many people don't realise their OS is the problem! 💪 |
I'm not sure my orignal problem is Windows related because I'm working with WSL (Ubuntu 20.04) on a Windows 11 computer. I think the problem must be same on a real Linux machine, even if I'm not 100% sure. I updated the "Playground link repo" in my first message to SWC 1.3.77 version, and the problem is a bit different: > test-nestjs@0.0.1 start
> nest start
✔ TSC Initializing type checker...
> TSC Found 0 issues.
> SWC Running...
thread '<unnamed>' panicked at 'base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.31/src/path.rs:104:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.31/src/path.rs:104:13
thread '<unnamed>' panicked at 'base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.31/src/path.rs:104:13
failed to handle: base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.
thread 'thread '<unnamed><unnamed>' panicked at '' panicked at 'base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.', ', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.31/src/path.rs/usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.31/src/path.rs::104104::1313
failed to handle: base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.
failed to handle: base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.
failed to handle: base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.
failed to handle: base_dir(./src) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.
Failed to compile 5 files with swc.
Error Failed to compile:
src/app.controller.spec.ts
src/app.controller.ts
src/app.module.ts
src/app.service.ts
src/main.ts Then if I do one of this action on my
> test-nestjs@0.0.1 start
> nest start
✔ TSC Initializing type checker...
> TSC Found 0 issues.
> SWC Running...
Successfully compiled: 5 files with swc (22.08ms)
Error: Cannot find module 'app.module'
Require stack:
- /home/kirian/Projects/Perso/test-nestjs/dist/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Function.Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/kirian/Projects/Perso/test-nestjs/dist/main.js:6:20)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) |
It's better! Now it can resolve But I have tried more things, and it seems to still not be perfectly working. I created a simple CRUD, and now I have this error: > test-nestjs@0.0.1 start
> nest start
✔ TSC Initializing type checker...
> TSC Found 0 issues.
> SWC Running...
Successfully compiled: 10 files with swc (31.16ms)
Error: Cannot find module 'users/users.service'
Require stack:
- /home/kirian/Projects/Perso/test-nestjs/dist/users/users.module.js
- /home/kirian/Projects/Perso/test-nestjs/dist/app.module.js
- /home/kirian/Projects/Perso/test-nestjs/dist/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Function.Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/kirian/Projects/Perso/test-nestjs/dist/users/users.module.js:12:23)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19) // app.module.ts
import { Module } from '@nestjs/common';
import { UsersModule } from 'users/users.module';
@Module({
imports: [UsersModule],
controllers: [],
providers: [],
})
export class AppModule {} // users.module.ts
import { Module } from '@nestjs/common';
import { UsersService } from 'users/users.service';
import { UsersController } from 'users/users.controller';
@Module({
controllers: [UsersController],
providers: [UsersService],
})
export class UsersModule {} // users.service.ts
import { Injectable } from '@nestjs/common';
import { CreateUserDto } from 'users/dto/create-user.dto';
import { UpdateUserDto } from 'users/dto/update-user.dto';
@Injectable()
export class UsersService {
create(createUserDto: CreateUserDto) {
return 'This action adds a new user';
}
findAll() {
return `This action returns all users`;
}
findOne(id: number) {
return `This action returns a #${id} user`;
}
update(id: number, updateUserDto: UpdateUserDto) {
return `This action updates a #${id} user`;
}
remove(id: number) {
return `This action removes a #${id} user`;
}
} I have tried several "paths" config, but didn't manage to make it works 😕 I'm not sure if it's any help, but the const common_1 = require("@nestjs/common");
const users_service_1 = require("./users.service");
const users_controller_1 = require("./users.controller"); But with SWC: const _common = require("@nestjs/common");
const _usersservice = require("users/users.service");
const _userscontroller = require("users/users.controller"); My repo is also up to date: https://github.com/KirianCaumes/nestjs-bug-swc-import |
@KirianCaumes I'm working on a fix for it with #7852 |
This comment was marked as off-topic.
This comment was marked as off-topic.
I'll mark it as off-topic as 1 and 2 are not related to this issue at all and 3 is a duplicate |
This comment was marked as spam.
This comment was marked as spam.
First, 1 is not a bug. And auto import has nothing to do with SWC |
I mean |
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry for inconvenience. But Nest Js sent the first person here to report. And I found my cases similar to him. So I also reported here. As I wasn't able to find the solution at stackoverflow as well. |
@m-nouman-munir Can you try v1.3.79 once https://github.com/swc-project/swc/actions/runs/5972622833 is finished?
|
1-Sure I'll Try that. 2- 2.5- I'M ON UBUNTU |
Actually, |
Yes, by reading all the above messages, I totally understood that. But my mistake I wasn't able to explain things clearly and put you under confusion. And also that's why I explained the entire point 1. As it was happening due to import issues, and also solved by itself when I changed things related to imports in |
Hey, thanks a lot! > test-nestjs@0.0.1 start
> nest start
✔ TSC Initializing type checker...
> TSC Found 0 issues.
> SWC Running...
Successfully compiled: 10 files with swc (29.65ms)
Error: Cannot find module 'node_modules/@nestjs/core/index.js'
Require stack:
- /home/kirian/Projects/Perso/test-nestjs/dist/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Function.Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/kirian/Projects/Perso/test-nestjs/dist/main.js:5:15)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) The import of "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const _core = require("node_modules/@nestjs/core/index.js");
const _appmodule = require("./app.module");
async function bootstrap() {
const app = await _core.NestFactory.create(_appmodule.AppModule);
await app.listen(5002);
}
bootstrap();
//# sourceMappingURL=main.js.map And I don't think it was prefixed with I also tried to edit My repo is up to date: https://github.com/KirianCaumes/nestjs-bug-swc-import |
I changed version in my package.json to |
I'm also finding |
So v.1.3.80 available now? |
It now works perfectly with version 1.3.80! |
@KirianCaumes or @kdy1 can you help me I'm still facing issue. I Installed latest SWC version.But When I try to build my project It does not get's build.And I face
**And If I do
Settings .swcrc
nest-cli.json
tsconfig.json
|
@KirianCaumes how your nest js versions are
mine are not going upward from
|
Hey @m-nouman-munir, Here is what I have: // package.json
{
"dependencies": {
"@nestjs/common": "^10.2.1",
"@nestjs/core": "^10.2.1",
},
"devDependencies": {
"@nestjs/cli": "^10.1.16",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.80",
} // nest-cli.json
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"builder": "swc",
"typeCheck": true
}
} // tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
} // .swcrc
{
"$schema": "https://json.schemastore.org/swcrc",
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"baseUrl": "./src",
"paths": {
"*": [
"*"
]
}
},
"minify": false
} // main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from 'app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(5002);
}
bootstrap(); // app.module.ts
import { Module } from '@nestjs/common';
import { UsersModule } from 'users/users.module';
@Module({
imports: [UsersModule],
controllers: [],
providers: [],
})
export class AppModule {} I hope that will help! You can also try to delete |
Does region matters for nest cli or core versions? |
As I mentioned before that your |
I changed |
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. |
Describe the bug
When I run
npm run start
(nest start
) in my project with NestJs 10 andswc
enabled, an error is thrown:Input code
No response
Config
Playground link
https://github.com/KirianCaumes/nestjs-bug-swc-import
Expected behavior
It should work the same way as without
swc
enabled and withbaseUrl
being used.Actual behavior
Import with non-relative modules are not found
Version
1.3.67
Additional context
I already posted an issue on NestJs, but they redirected me here.
The text was updated successfully, but these errors were encountered: