Open utterances-bot opened 1 year ago
Hi, congratulations for your post is awesome.
Follow every step but when start up server, nestJs show me a error in the logs
Error: Cannot find module 'module-alias/register'
micropetid_service | Require stack:
micropetid_service | - /usr/src/app/dist/src/main.js
micropetid_service | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
micropetid_service | at Function.Module._load (node:internal/modules/cjs/loader:778:27)
micropetid_service | at Module.require (node:internal/modules/cjs/loader:1005:19)
micropetid_service | at require (node:internal/modules/cjs/helpers:102:18)
micropetid_service | at Object.
Can you help me?!
add this
require("module-alias/register");
to the top of main.ts
Yes, add this line on the top of main.ts, but have the same error.
On Sun, 27 Nov 2022 at 5:38 AM tarun @.***> wrote:
add this
require("module-alias/register");
to the top of main.ts
— Reply to this email directly, view it on GitHub https://github.com/tkssharma/comments/issues/12#issuecomment-1328217568, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIJGR7QNU4JHASYZN6O6T63WKM223ANCNFSM6AAAAAASMLBYYU . You are receiving this because you commented.Message ID: @.***>
-- Brayan Andrés Sanjuan Guerrero Ingeniero en Mecatrónica Cel. 3508119060
strange but lets see what is missing here Its a simple module which looks for the alias we have created in package json
npm module
"module-alias": "2.2.2"
This must be in your package JSON (path should point to your build output)
"_moduleAliases": {
"@auth": "build/api/auth",
"@core": "build/api/core",
"@lib": "build/api/lib",
"@domains": "build/api/domains",
"@proxy": "build/api/proxy"
},
tsconfig
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"sourceMap": true,
"outDir": "./build",
"baseUrl": "./src",
"incremental": true,
"skipLibCheck": true,
"paths": {
"@auth/*": ["api/auth/*"],
"@core/*": ["api/core/*"],
"@lib/*": ["api/lib/*"],
"@domains/*": ["api/domains/*"],
"@proxy/*": ["api/proxy/*"]
}
}
}
if this does not help will add a simple app as Demo
Its works!!!.
Thanks for your help.
Brayan Andrés Sanjuan Guerrero Ingeniero en Mecatrónico Cel. 350 8119060 On 27 Nov 2022, 12:49 -0500, tarun @.***>, wrote:
strange but lets see what is missing here Its a simple module which looks for the alias we have created in package json
• tsconfig points to the src path • package json will point to the build path its can be a build dir or dist based on dist config
npm module "module-alias": "2.2.2" This must be in your package JSON (path should point to your build output) "_moduleAliases": { @.": "build/api/auth", @.": "build/api/core", @.": "build/api/lib", @.": "build/api/domains", @.***": "build/api/proxy" },
tsconfig
{ "extends": @./node14/tsconfig.json", "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "allowSyntheticDefaultImports": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "strictPropertyInitialization": false, "sourceMap": true, "outDir": "./build", "baseUrl": "./src", "incremental": true, "skipLibCheck": true, "paths": { @./": ["api/auth/"], @./": ["api/core/"], @./": ["api/lib/"], @./": ["api/domains/"], @./": ["api/proxy/"] } } } if this does not help will add a simple app as Demo — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Nest JS Module aliasing using module-alias – @tkssharma | Tarun Sharma | My Profile
A Simple Way To Use Path Aliases in NestJS I am talking about this whenever we write code most of teh times we end up using whole path…
https://tkssharma.com/nestjs-module-path-aliases-moduel-imports/