Can't deploy Nestjs to Heroku - api

I'm trying to deploy a nestjs app to heroku but I get this error in the logs
2022-09-03T16:19:06.793730+00:00 app[web.1]: > pokedex#0.0.1 start:prod
2022-09-03T16:19:06.793731+00:00 app[web.1]: > node dist/main
2022-09-03T16:19:06.793731+00:00 app[web.1]:
2022-09-03T16:19:06.859243+00:00 app[web.1]: node:internal/modules/cjs/loader:959
2022-09-03T16:19:06.859244+00:00 app[web.1]: throw err;
2022-09-03T16:19:06.859245+00:00 app[web.1]: ^
2022-09-03T16:19:06.859245+00:00 app[web.1]:
2022-09-03T16:19:06.859245+00:00 app[web.1]: Error: Cannot find module '/app/dist/main'
2022-09-03T16:19:06.859246+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
2022-09-03T16:19:06.859247+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:804:27)
2022-09-03T16:19:06.859247+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
2022-09-03T16:19:06.859247+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 {
2022-09-03T16:19:06.859248+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-09-03T16:19:06.859248+00:00 app[web.1]: requireStack: []
2022-09-03T16:19:06.859249+00:00 app[web.1]: }
I created a Procfile with npm run start:prod command, also tried moving #nestjs/cli devDependency to dependencies but it doesn't work

Next js goes perfectly with vercel if you are not bounded with a single option to deploy

Apparently Nest.js build the main.js in dist/src/
I also created a Procfile with web: npm run start:prod to run the app

The start:prod command in the package.json should be updated to read "start:prod": "node dist/src/main" due to how the project is built. Usually this means that there is a ts file outside of src that is being read as a part of the project, or some other import is happening to a file outside of the source root

Related

Using npm to install puppetteer gives Error: Cannot find module 'puppeteer/internal/node/install.js'

Trying to install puppeteer on Centos 7
npm i puppeteer
> puppeteer#19.4.1 postinstall /mypath/node_modules/puppeteer
> node install.js
internal/modules/cjs/loader.js:775
throw err;
^
Error: Cannot find module 'puppeteer/internal/node/install.js'
Require stack:
- /mypath/node_modules/puppeteer/install.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
at Function.Module._load (internal/modules/cjs/loader.js:677:27)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/mypath/node_modules/puppeteer/install.js:38:27)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/mypath/node_modules/puppeteer/install.js'
]
}
It doesn't seem to have downloaded anything into the node_modules/ directory, which I think "npm i" should do, and all of the tutorials I have read do not ask you perform any action or download, before running the npm command.
What do I need to do, to make this install puppeteer? (with chrome)
I was getting this error because my node version was too old (version 10) but fixed it by switching to version 16.
To fix this I used nvm from the command line as follows:
nvm use 16
nvm alias default 16

Cyclic.sh is not detecting the start scrypt in package.json

I came here after some hours of reading and getting into the cyclic cool deployment process. https://www.cyclic.sh/
I was trying to host my express js app for free and linked my github repo to my cyclic.sh dashboard. (I added typescript to my express app btw) The build process of my app was successful ✅ , but when I check the logs on runtime it throws me this error: ERROR: Failed to run 'node index.js'
Successful build:
enter image description here
The complete error log in runtime:
2023-01-09 01:21:26.063: grep: /var/task/package.json: No such file or directory
2023-01-09 01:21:26.527: node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module 'dotenv'
Require stack:
- /var/task/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/var/task/index.js:33:34)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/var/task/index.js' ]
}
Thrown at:
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
2023-01-09 01:21:26.527: at require (node:internal/modules/cjs/helpers:103:18)
at /var/task/index.js:33:34
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at executeUserEntryPoint (node:internal/modules/run_main:81:12)
Node.js v18.12.1
2023-01-09 01:21:26.562:
ERROR: Failed to run 'node index.js'.
Exited with code: 1
I noticed that the problem is that cyclic is not running node in the correct directory. The correct command executed should be: node dist/index.js. Because of that, I added the scripts configuration in my package.json as it is specified in https://docs.cyclic.sh/overview/launch, but for some reason cyclic is not reading that change in my scripts. (It works well locally)
I am not sure if I am missing something. I am very close, but I am stock at this point. I attatched some screenshots about the successful build, the failure and my package.json configuration.
My package.json file configuration:
enter image description here
Any help would be very appreaciated! Thanks in advance!

VUe.js run serve failing after installation

I have installed Vue on my terminal with :
sudo npm install -g #vue/cli
After that , I created a project, moved into the folder and tried to run the server :
vue create frontend
cd frontend
npm run serve
So , I didn't change anything from the presets but I can't launch my server and I get the following error :
ERROR Failed to compile with 1 error 21:56:21
error in ./src/App.vue?vue&type=script&lang=js
Syntax Error: RangeError: /home/simao/Desktop/chess_DB/frontend/src/App.vue: Maximum call stack size exceeded
at Array.map (<anonymous>)
at Array.map (<anonymous>)
at Array.map (<anonymous>)
at Array.map (<anonymous>)
at Array.map (<anonymous>)
# ./src/App.vue?vue&type=script&lang=js 1:0-262 1:0-262 1:263-514 1:263-514
# ./src/App.vue
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.1.19:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
I looked into App.vue and main.js but this feels strange since I haven't touched the files after installing vue. Any idea what it might be ?
Vue version : #vue/cli 4.5.15
node : v16.14.0
OS : Ubuntu 20.04
Thats cannot be a problem but maybe is difference between 'npm runserve' and 'npm run serve' command?

when running npm run build on lunix it's not working

when running : npm run build on lunix server i got :
Error: Cannot find module :
'/usr/home/html/production/libs/laravel/app_inventory_v2/front/node_modules/#vue/cli-plugin-router/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (node:internal/modules/cjs/loader:353:19)
at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at idToPlugin (/usr/home/html/production/libs/laravel/app_inventory_v2/front/node_modules/#vue/cli-service/lib/Service.js:145:14)
at /usr/home/html/production/libs/laravel/app_inventory_v2/front/node_modules/#vue/cli-service/lib/Service.js:184:20
at Array.map ()
at Service.resolvePlugins (/usr/home/html/production/libs/laravel/app_inventory_v2/front/node_modules/#vue/cli-service/lib/Service.js:170:10) {
code: 'MODULE_NOT_FOUND',
path: '/usr/home/html/production/libs/laravel/app_inventory_v2/front/node_modules/#vue/cli-plugin-router/package.json',
requestPath: '#vue/cli-plugin-router'
Several things that might be checked:
Verify you don't include the node_modules directory from your development host. It may contain binaries that are only meant for specific platforms.
Perform a clean installation by running the npm ci command on your production host. Verify you have stored package.json and package-lock.json on the server.

snack-web from expo is not working locally

I have cloned the repo for snack-web locally.
Followed the instructions as mentioned in the Readme.
But getting below issue:
$ if-env NODE_ENV=production && yarn start:prod || yarn start:dev
$ yarn domain
$ hotel start && hotel add http://localhost:3011 --name snack.expo
Started http://localhost:2000
Create ~\.hotel\servers\snack.expo.json
$ nodemon -e json,js,ts,tsx --watch src/server src/server/index.tsx --exec babel-node --extensions '.ts,.tsx'
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): src\server\**\*
[nodemon] watching extensions: json,js,ts,tsx
[nodemon] starting `babel-node src/server/index.tsx --extensions '.ts,.tsx'`
D:\projects\snack-web\src\server\index.tsx:3
import path from 'path';
^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at Object.<anonymous> (D:\projects\snack-web\node_modules\#babel\node\lib\_babel-node.js:174:21)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
[nodemon] app crashed - waiting for file changes before starting...
Issue is already opened in github, but no reply.
Does anyone here on SO help me resolve this issue? Or help understand what is the real cause? Any workarounds?
Thanks!!
I think because of single quote in start:dev command. cmd does't support single quote.
try change package.json line 9 to this
"start:dev": "nodemon -e json,js,ts,tsx --watch src/server src/server/index.tsx --exec babel-node --extensions \".ts,.tsx\"",