When i running npm run typeorm migration:generate -- -n CreateUserTable migration successfully generates, but at the same time my project is starting. When i running migration:create all works fine and project doesn't starts.
I tried
change ts-node to node.
run npx typeorm instead of npm run typeorm
changing dist folder to src
create mig:gen scripts
Here's error log
> ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli "migration:generate" "-n" "CreateUserTable"
[Nest] 6648 - 2022-01-27 19:23:24 LOG [NestFactory] Starting Nest application...
[Nest] 6648 - 2022-01-27 19:23:24 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
AlreadyHasActiveConnectionError: Cannot create a new connection named "default", because connection with such name already exist and it
now has an active connection session.
at AlreadyHasActiveConnectionError.TypeORMError [as constructor] (C:\Users\whitered932\Projects\wr-todo\src\error\TypeORMError.ts:7
:9)
at new AlreadyHasActiveConnectionError (C:\Users\whitered932\Projects\wr-todo\src\error\AlreadyHasActiveConnectionError.ts:8:9)
at ConnectionManager.create (C:\Users\whitered932\Projects\wr-todo\src\connection\ConnectionManager.ts:57:23)
at C:\Users\whitered932\Projects\wr-todo\src\globals.ts:77:35
at step (C:\Users\whitered932\Projects\wr-todo\node_modules\tslib\tslib.js:143:27)
at Object.next (C:\Users\whitered932\Projects\wr-todo\node_modules\tslib\tslib.js:124:57)
at fulfilled (C:\Users\whitered932\Projects\wr-todo\node_modules\tslib\tslib.js:114:62)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
[Nest] 6648 - 2022-01-27 19:23:24 LOG [InstanceLoader] AppModule dependencies initialized +7ms
[Nest] 6648 - 2022-01-27 19:23:24 LOG [InstanceLoader] TypeOrmModule dependencies initialized +2ms
Migration C:\Users\whitered932\Projects\wr-todo/src/migrations/1643293402567-CreateUserTable.ts has been generated successfully.
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +3152ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TypeOrmModule dependencies initialized +2ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] UserModule dependencies initialized +3ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TaskModule dependencies initialized +1ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RoutesResolver] TaskController {/task}: +344ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task, GET} route +5ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task/:id, GET} route +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task, POST} route +2ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task/:id, PATCH} route +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task/:id, DELETE} route +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RoutesResolver] UserController {/user}: +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [NestApplication] Nest application successfully started +7ms
Завершить выполнение пакетного файла [Y(да)/N(нет)]? Y
Here's my files
package.json scripts
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
},
ormconfig.json
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "postgres",
"database": "postgres",
"entities": ["dist/**/*.js"],
"migrations": ["dist/migrations/*.js"],
"cli": {
"migrationsDir": "src/migrations"
}
}
Try adding keepConnectionAlive in your ormconfig.json file
Related
Good day everyone!
I have an old app from dev that now isn't working in our company. I need to start this app but don't have enough experience in NodeJS (I don't have it at all, TBH).
The problem is: I can build a docker image, start it, and use the app, but when I make something that requires to make a request to MQSQL server, the app crashes.
But there are no issues with requests to Postgres DB.
This is my docker build output
docker build -t fixver .
Sending build context to Docker daemon 2.427MB
Step 1/21 : FROM node:16-alpine as base
---> c4ee3c9d7bc1
Step 2/21 : ARG NODE_ENV=production
---> Using cache
---> ba79cfac2e2c
Step 3/21 : ENV NODE_ENV=${NODE_ENV} NODE_OPTIONS="--max_old_space_size=8192"
---> Using cache
---> 1a344f8791d8
Step 4/21 : WORKDIR /usr/src/app
---> Using cache
---> 1c591a772bcd
Step 5/21 : FROM base as clientBuilder
---> 1c591a772bcd
Step 6/21 : COPY ./client/package.json ./client/yarn.lock ./
---> Using cache
---> 7382b944fcc0
Step 7/21 : RUN yarn install --production=false --frozen-lockfile
---> Using cache
---> 431700be035b
Step 8/21 : COPY ./client .
---> Using cache
---> 87790e7c061a
Step 9/21 : RUN yarn build
---> Using cache
---> 9ba70dd8301c
Step 10/21 : FROM base as serverBuilder
---> 1c591a772bcd
Step 11/21 : COPY ./server/package.json ./server/yarn.lock ./
---> Using cache
---> bf5dc70ee2eb
Step 12/21 : RUN yarn install --production=false --frozen-lockfile
---> Using cache
---> c26b02f2af5c
Step 13/21 : COPY ./server .
---> 16fdc772d650
Step 14/21 : RUN yarn build
---> Running in 676753d20a77
yarn run v1.22.19
$ node_modules/.bin/rimraf dist
$ node_modules/.bin/nest build
Done in 5.75s.
Removing intermediate container 676753d20a77
---> 66a53b6af7cd
Step 15/21 : FROM base as production
---> 1c591a772bcd
Step 16/21 : COPY ./server/package.json ./server/.env ./
---> dbbbe7295cfd
Step 17/21 : RUN yarn install --pure-lockfile
---> Running in f3b965d1ec0d
yarn install v1.22.19
info No lockfile found.
[1/4] Resolving packages...
warning Resolution field "uuid#8.3.2" is incompatible with requested version "uuid#^3.1.0"
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > w3c-hr-time#1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > ts-loader#9.4.2" has unmet peer dependency "webpack#^5.0.0".
[4/4] Building fresh packages...
Done in 39.04s.
Removing intermediate container f3b965d1ec0d
---> 8d804071a8d2
Step 18/21 : COPY --from=serverBuilder /usr/src/app/dist ./
---> f760fda4b1a1
Step 19/21 : COPY --from=clientBuilder /usr/src/app/build ./public
---> 4f697bab8bc6
Step 20/21 : EXPOSE 80
---> Running in 95fae0df9266
Removing intermediate container 95fae0df9266
---> 4bebff7957bc
Step 21/21 : CMD ["node", "./main"]
---> Running in 19b4df36b37e
Removing intermediate container 19b4df36b37e
---> 362fbadf0b4a
Successfully built 362fbadf0b4a
Successfully tagged fixver:latest
Starting the app
docker run -p 7007:80 fixver
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [NestFactory] Starting Nest application...
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] AppModule dependencies initialized +60ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] PassportModule dependencies initialized +1ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] ServeStaticModule dependencies initialized +0ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] ConfigModule dependencies initialized +1ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] AuthModule dependencies initialized +8ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] PagesModule dependencies initialized +0ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [InstanceLoader] ScriptsModule dependencies initialized +1ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [RoutesResolver] ScriptsController {/api/scripts}: +8ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [RouterExplorer] Mapped {/api/scripts, GET} route +4ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [RouterExplorer] Mapped {/api/scripts/:id, GET} route +1ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [RouterExplorer] Mapped {/api/scripts/:id/check, POST} route +0ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [RouterExplorer] Mapped {/api/scripts/:id/apply, POST} route +1ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [RoutesResolver] PagesController {/api/pages}: +1ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [RouterExplorer] Mapped {/api/pages/:id, GET} route +0ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG [NestApplication] Nest application successfully started +5ms
[Nest] 1 - 12/01/2022, 1:49:54 PM LOG Server started! Port: 80
And error right after making request to MSSQL
node:events:491
throw er; // Unhandled 'error' event
^
Error: No event 'featureExtAck' in state 'SentLogin7WithNTLMLogin'
at Connection.dispatchEvent (/usr/src/app/node_modules/tedious/lib/connection.js:1663:26)
at Parser.<anonymous> (/usr/src/app/node_modules/tedious/lib/connection.js:1224:12)
at Parser.emit (node:events:513:28)
at Readable.<anonymous> (/usr/src/app/node_modules/tedious/lib/token/token-stream-parser.js:27:14)
at Readable.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Readable.push (node:internal/streams/readable:228:10)
at next (node:internal/streams/from:98:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Readable instance at:
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
I really don't know what to do with it, how to debug it and find the problem.
Any help and advise is appreciated.
Problem was solved by changing this code in Dockerfile
-COPY ./server/package.json ./server/.env ./
-RUN yarn install --pure-lockfile
+COPY ./server/package.json ./server/yarn.lock ./server/.env ./
+RUN yarn install --production=true --frozen-lockfile
I am trying to run my nest.js app by
function log(s: any) {
fs.appendFileSync('./serverStart.log', JSON.stringify(s) + "\n");
}
async function bootstrap() {
try {
const app = await NestFactory.create(AppModule);
log("app created")
app.setGlobalPrefix('api');
log("app set prefix")
await app.listen(0);
log("started")
} catch (e) {
log(e);
}
}
bootstrap();
that works nicely locally and used to work nicely with cpanel node-selector at my hoster until two days ago when I suspect my hoster changed sth, though they deny it. However now I get the follwowing error in my log file for the await app.listen(0) command
{"errno":-17,"code":"EEXIST","syscall":"uv_pipe_open"}
I am not sure what to make of it and a search did not result in anything meaningfull? Any ideas someone?
Could it be sth is already listening on the port (wild guess) and if so how can fix that?
Simple erxpress app works like the one below work at my hoster
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var response = "All good";
res.end(response);
});
server.listen();
So it seems to be some interworking issue between cpanel and nest
UpdatE: I investigated further and found
calling $ node /home/dasdding/nestbasic/dist/main.js the app is nicely started on my hosters environment
"starting "
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [NestFactory] Starting Nest application...
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [InstanceLoader] AppModule dependencies initialized +33ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [InstanceLoader] HttpModule dependencies initialized +4ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [InstanceLoader] MetricsModule dependencies initialized +0ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [InstanceLoader] TerminusModule dependencies initialized +1ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [InstanceLoader] HealthModule dependencies initialized +0ms
"create app "
"prefix done"
"init done"
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [RoutesResolver] HealthController {/nestbasic/health}: +5ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [RouterExplorer] Mapped {/nestbasic/health, GET} route +2ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [RouterExplorer] Mapped {/nestbasic/health/storage, GET} route +1ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [RouterExplorer] Mapped {/nestbasic/health/memory, GET} route +0ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [RouterExplorer] Mapped {/nestbasic/health/main4shops, GET} route +1ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [RoutesResolver] MetricsController {/nestbasic/metrics}: +0ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [RouterExplorer] Mapped {/nestbasic/metrics, GET} route +0ms
[Nest] 879990 - 11/25/2022, 5:21:05 PM LOG [NestApplication] Nest application successfully started +3ms
"now listening "
"http://[::1]:45611"
Buit when starting it via capnel i still get the error. According to https://www.quora.com/What-is-EINVAL-in-Linux this EINVAL means invalid argument passed.
So I check what arguments are being passed and found it to be ["/opt/alt/alt-nodejs16/root/usr/bin/node","/usr/local/lsws/fcgi-bin/lsnode.js"]
Comparing that to the call when I just run node ..../main.js I see a difference. Running node .../main.js as expected I get
["/opt/alt/alt-nodejs16/root/usr/bin/node","/home/dasdding/nestbasic/dist/main.js"]
Doing a cat /usr/local/lsws/fcgi-bin/lsnode.js I see that the script executed by cpanel is not directly my script but sth that appears to be some sort of a wrapper that mentions " Copyright 2002-2018 Lite Speed Technologies Inc, All Rights Reserved. * LITE SPEED PROPRIETARY/CONFIDENTIAL" I.e. from an app developers perspective that knows his app but not cpanel wrapping cpanel is not calling my script but doing sth different that results in an invalid parameter exeception.
Since previously nest.js and cpanel worked together and now they dont I conclude that this is a incompatibility between cpanel and nest.js that must have recently been introduced, since it worked before (config change or code - not sure).
Since in my deployment of my app I use the defined versions in the package-lock of packages and install via npm ci (thus using the exact versions from the package-lock and tried deployment with a commit if package-lock where it worked I conclude that it is most likey a recent chagne in cpanel/node-selector config or code. Or do I misunderstand npm ci and package-lock,json working together?
Is there anybody from cpanel here to comment? Will also post in cpanel forum...
Update: Has been fixed by my hoster. Was an issue with the litespeed servers and a reinstall solved the issue.
Cheers
Tom
I am currently building an application using NestJS by following microservice architecture. And use NATS as a messaging system. It works fine on my local machine but I am unable to dockerized the NATS server.
The folder structure of my project:
├─── services/
├─── nats/
| Dockerfile
├─── client/
| ...
| ...
| .dockerignore
| Dockerfile
└─── docker-compose.yml
Now, the Dockerfile inside nats/ folder describes as below:
FROM nats:2.1.9
EXPOSE 4222
CMD [ "nats-server" ]
And Dockerfile inside client/ folder describes as:
FROM node:12
WORKDIR /myProject/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8081
CMD [ "node", "dist/main" ]
And the docker-compose.yml is:
version: '3'
services:
nats-server:
image: nats:2.1.9
restart: always
build: ./nats
ports:
- 4222:4222
client-service:
build: ./client
volumes:
- ./client:/myProject/src/app
depends_on:
- nats-server
environment:
NODE_ENV: development
ports:
- 8081:3000
I've run the command sudo docker-compose build and found no error, after that run the command sudo docker-compose up and found the following error:
Recreating services_nats-server_1 ... done
Recreating services_client-service_1 ... done
Attaching to services_nats-server_1, services_client-service_1
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
services_nats-server_1 exited with code 1
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [NestFactory] Starting Nest application...
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] AppModule dependencies initialized +41ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] MongooseModule dependencies initialized +1ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ClientsModule dependencies initialized +1ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ClientsModule dependencies initialized +0ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ConfigHostModule dependencies initialized +1ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ConfigModule dependencies initialized +1ms
services_nats-server_1 exited with code 1
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
There is no problem with the client service Dockerfile, as it depends on the nats-server tried to run it first. Can anyone please help me to figure out the problem?
I would like to thank you for your time and consideration.
The build: command for the nats-server service has overwritten the Docker Hub image. I just need to pull the image and expose the port.
So, my docker-compose.yml file will be as following:
version: '3'
services:
nats-server:
image: nats:2.1.9
restart: always
ports:
- 4222:4222
client-service:
build: ./client
volumes:
- ./client:/myProject/src/app
depends_on:
- nats-server
environment:
NODE_ENV: development
ports:
- 8081:3000
Check the Dockerfile and you'll notice that ENTRYPOINT is set to /nats-server and CMD is the parameters to ENTRYPOINT (--config nats-server.conf in that case).
Unless you extend the nats image you don't need to build a new one based on it (remove build: ./nats from the compose file). Overriding the default CMD can be achieved by setting command: on the docker-compose.yml.
I deploy a NestJS Application to Heroku and get H10 Error
Log:
2020-05-07T13:12:51.967622+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-07T13:15:14.556288+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=scalenode.herokuapp.com request_id=535e5643-26ad-4fbe-acf3-7f805c8c463c fwd="91.64.79.140" dyno= connect= service= status=503 bytes= protocol=https
Its stunning, because the Error comes because of GET Request. Node has been compiled successfully. I deployed via HerokuCli and Github. Both has the same result. But if I test it with HerokuCli locally with heroku local web, it works.
It does not seems to be a deployment error itself, its seems to be the route / cant be resolved so the app crashes. When I open the app in browser after successfully deploy, it seems to be a timeout.
Here is the Repo. I have a 'Hello World' string on / route. I cant find out whats wrong.
I use a Procfile for the instance, which seems to be fine:
web: node dist/main.js
EDIT:
I tried to have a static HTML Response and tried stable Node Version 12.x.
I dont get it
2020-05-07T14:22:40.862206+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RoutesResolver] [39m[32mAppController {}:[39m[38;5;3m +6ms[39m
2020-05-07T14:22:40.865503+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {, GET} route[39m[38;5;3m +3ms[39m
2020-05-07T14:22:40.865886+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RoutesResolver] [39m[32mAuthController {}:[39m[38;5;3m +0ms[39m
2020-05-07T14:22:40.867140+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {/auth/login, POST} route[39m[38;5;3m +2ms[39m
2020-05-07T14:22:40.867778+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {/profile, GET} route[39m[38;5;3m +0ms[39m
2020-05-07T14:22:40.868162+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RoutesResolver] [39m[32mFilesController {/files}:[39m[38;5;3m +1ms[39m
2020-05-07T14:22:40.868999+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {/files/upload, POST} route[39m[38;5;3m +0ms[39m
2020-05-07T14:22:40.873240+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[NestApplication] [39m[32mNest application successfully started[39m[38;5;3m +5ms[39m
2020-05-07T14:22:42.000000+00:00 app[api]: Build succeeded
It doesnt work... i cant find more details in logs, nothing more concrete. What the hell is going wrong...
In main.ts, have you tried changing the port number? To something like:
app.listen(parseInt(process.env.PORT) || 3000)
Since Heroku will try to use its own port. Maybe this could work too:
const port: number = parseInt(`${process.env.PORT}`) || 3000;
await app.listen(port);
Did you try setting heroku config variable NPM_CONFIG_PRODUCTION to false?
You can try this by going to your heroku dashboard -> settings -> reveal config vars, and then add the value above.
This error happens mainly because NestJS relies on some devDependencies in your project, and heroku removes devDependencies when building your Nest app if you're building in production mode. Setting NPM_CONFIG_PRODUCTION config to false would include all your dev dependencies in the Nest app's build process, just like building for a development environment. Alternatively, you can selectively move your nest related devDependencies to dependencies in package.json until the problem is gone.
Let me know if it works!
I am trying to dubug my app using debug package through nodemon package and I am facing this much trouble that my required output is hidden inside the messy irrelevant information as you can see
Error / Issue
[nodemon] restarting due to changes...
nodemon bus emit: restart +25s
nodemon bus new listener: start (0) +0ms
nodemon bus new listener: start (0) +1ms
[nodemon] starting `node ./build/index.js`
nodemon fork C:\Windows\system32\cmd.exe /d /s /c node ./build/index.js +25s
nodemon bus emit: start +5ms
nodemon bus new listener: exit (2) +1ms
nodemon start watch on: *.* +2ms
[nodemon] restarting due to changes...
nodemon bus emit: restart +4ms
nodemon bus.emit(exit) via SIGUSR2 +218ms
nodemon bus emit: exit +215ms
[nodemon] starting `node ./build/index.js`
nodemon fork C:\Windows\system32\cmd.exe /d /s /c node ./build/index.js +5ms
nodemon bus emit: start +5ms
nodemon bus new listener: exit (1) +1ms
nodemon start watch on: *.* +2ms
app:normal it is normal debugger... +0ms
Listening on port: 3000
^CTerminate batch job (Y/N)? y
E:\Web Apps\RESTful API\express-demo>nodemon ./build/index.js
nodemon bus new listener: reset (0) +0ms
nodemon bus new listener: reset (0) +3ms
nodemon bus new listener: quit (0) +26ms
nodemon bus new listener: quit (0) +0ms
nodemon bus new listener: restart (0) +1ms
nodemon bus new listener: restart (0) +0ms
nodemon bus new listener: reset (2) +6ms
nodemon bus emit: reset +1ms
nodemon resetting watchers +0ms
nodemon reset +0ms
nodemon config: dirs [ 'E:\\Web Apps\\RESTful API\\express-demo' ] +0ms
[nodemon] 1.17.3
[nodemon] to restart at any time, enter `rs`
nodemon bus new listener: error (0) +106ms
nodemon bus new listener: error (0) +0ms
[nodemon] watching: *.*
[nodemon] starting `node ./build/index.js`
nodemon fork C:\Windows\system32\cmd.exe /d /s /c node ./build/index.js +0ms
nodemon bus new listener: exit (0) +12ms
nodemon bus new listener: exit (0) +1ms
nodemon start watch on: *.* +3ms
nodemon start watch on: E:\Web Apps\RESTful API\express-demo +119ms
nodemon ignored [ '**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**',
re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/ ] +1ms
nodemon watch is complete +147ms
app:normal it is normal debugger... +0ms
Listening on port: 3000
I am following these commands to debug my app
Inside index.js
const debug = require('debug')('app:start')
debug('debugging the app... Yup!')
Inside Terminal
set DEBUG=app:start // inside terminal
nodemon index.js // inside terminal
Issue was very silly that I was running these two commands in different terminals that cause the problem
set DEBUG=app:start // inside terminal
nodemon index.js // inside terminal
be sure to run these commands in the same terminal.
Hope this will save time for someone.