Reputation: 31345
I'm trying to run a typescript project in production mode. The code is here on Github
npm run start:dev
is running the server up on http://localhost:3000/npm run build
is generating the dist
folderThe package.json
has the definition of @server
defined using module alias:
"_moduleAliases": {
"@server": "dist/Server"
}
The @server
is defined under compilerOptions.paths.@server
in tsconfig.json
too!
The index.ts
imports app
from @server
;
import app from '@server';
When I run npm start
- it does nothing
So I tried node dist/index.js --env=production
and it throws the following error:
Error: Cannot find module '@server'
Why is the node not detecting this module alias?
Upvotes: 3
Views: 12067
Reputation: 35560
As stated on the module-alias
README, it changes the default behavior of require
. So, to use it, you have to add require('module-alias/register')
to the beginning of your code before you import anything. I would suggest adding it to LoadEnv.ts
.
Upvotes: 9