Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-3
rated 0 times [  4] [ 7]  / answers: 1 / hits: 7211  / 4 Years ago, thu, june 18, 2020, 12:00:00

I'm trying to run a typescript project in production mode. The code is here on Github




  • Running npm run start:dev is running the server up on http://localhost:3000/

  • Running npm run build is generating the dist folder



The 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?


More From » node.js

 Answers
8

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.


[#3442] Tuesday, June 16, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Oct 23, 19, 00:00, 5 Years ago
;