I started using Nest.Js and I created a Full Stack App with this structure:
api
: nestjs appclient
: frontend appmodels
: shared models (interfaces only) between back and front
So I set alias path in tsconfig.json
inside api folder to let it import shortly: import { User } from 'models/user.model'
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"incremental": true,
"outDir": "./dist",
"baseUrl": "./",
"paths": {
"models/*": ["../models/*"]
}
}
}
The problem is that typescript is compiling and changing the root structure under dist
folder and nest cli is not finding main.js
file to start up the application.
Is there a way to move models
folder and preserve nestjs structure?
Or maybe change nestjs config to start the app on api/src/main.js
?
This is something typescript does when there is code outside of the root src
directory, to make sure that after compilation the same paths can be used. You can modify the nest-cli.json
and add an entryFile
property to tell Nest where the main
file is. Also, consider something like Nx
to help with creating fullstack monorepos.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With