Getting error on deploying nestjs app on gcloud - google-app-engine

Getting error on deploying nestjs app on google app engine. The deployment worked fine but app is giving error
Here is the my package.json file
"main": "dist/main.js",
"engines": {
"node": ">=8.0.0"
},
"scripts": {
"prebuild": "rimraf dist",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "node ./dist/main.js",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "tslint -p tsconfig.json -c tslint.json",
"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",
"build": " tsc -p tsconfig.build.json",
"gcp-build": "npm run build"
},
and this my app.yaml file
runtime: nodejs10
env: standard
I tried to see the error on gcloud console by gcloud app logs read and it gives me error in cjs/loader file
The app is working fine locally. Any reason why this is happening?

Error: Cannot find module 'src/utils'
It looks like you are using non-relative imports and using src as a root, which won't work once you have transpiled from typescript to javaScript without some extra modifications. The src directory shouldn't exist when you are in your production environment, only the dist that has your JavaScript. If you change the import to be a relative one (using .. to get tot the correct directory from where you are) it should work just fine

Related

Unable to run the script in nest js getting missing script error

I have added the script in my packege.json file,but when trying to run in terminal by using command " npm run seed:ambassadors " it gives error missing script ,
Error:
npm ERR! missing script: seed:ambassadors
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-12-29T11_33_08_599Z-debug.log
docker-compose.yaml
packege.json
"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",
"seed:ambassadors": "ts-node src/command/ambassador.seeder.ts"
},
NOTE: I am running that "npm run seed:ambassadors" commad in docker container and to run docker container I am using "docker-compose exec backend sh".
any suggestion plzzzz?????

Getting 404 page while serving the build of the NextJs App while its running fine in the development mode

I am pretty new to React/Next JS. So here's my issue. I have purchased a theme and made changes to the config and branding part. Now when I run the app using "yarn dev" and "yarn start", it is working fine. "yarn build" also creates an optimized production build. I wanted to deploy the app locally in my PC and i was trying to learn things through youtube videos. so in one of the videos i found this command ("prod": "next build && serve build") to include in package.json. my package.json file has the following scripts.
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"export": "next export",
"lint": "eslint --fix "src//*.{js,jsx}"",
"format": "prettier --write "src//*.{js,jsx}"",
"prod": "next build && serve build"
},
so when i try with "yarn prod", it is first creating an optimized build and then i get the following output in the vscode terminal
however if i try to open "http://localhost:3000" in my browser. i get 404 error. but not with "yarn dev" or "yarn start". no error while building the app too.

yarn start:all command working for mac but throwing error in windows system for same package.json scripts values

I am trying to start a react and node based application that works fine in mac systems, but when I am trying to start in windows, it's throwing an error.
The command to start is - yarn start:all
The script entries in package.json file are -
"scripts": {
"docs": "jsdoc2md src/*.js src/**/*.js > API.md",
"build:dev": "better-npm-run build:dev",
"build:production": "better-npm-run build:production",
"style": "eslint --fix --ext .js,.jsx src config",
"unit": "cross-env LOG_LEVEL=warn jest",
"coverage": "cross-env LOG_LEVEL=warn helix test --coverage",
"test": "yarn style && yarn coverage",
"start:inspect": "nodemon --inspect .",
"eject": "helix eject",
"start": "better-npm-run start:stage",
"start:ordersPresentationStage": "micro_cancellations_path=http://localhost:3001/cancellations/micro yarn --cwd ../orders-presentation-helix startStage",
"start:laptopProxyServer": "node tools/laptopDevProxyServer.js",
"start:all": "concurrently --kill-others -n proxy,orders,cancellation \"yarn start:laptopProxyServer\" \"yarn start:ordersPresentationStage\" \"yarn start\"",
"start:production": "yarn run build:production && cross-env ASSET_PATH=/cancellationspres/assets/ NODE_ENV=production node .",
"build-stats:development": "yarn start -- --analyze",
"build-stats:production": "yarn build -- --analyze",
"generate:component": "helix generate:component",
"clean": "rimraf ./build",
"std-version": "standard-version"
},
The error that I am getting is -
'micro_cancellations_path' is not recognized as an internal or external command, operable program or batch file.
I assume the start:ordersPresentationStage part of scripts is unable to execute because the line cannot be processed in windows system, but I am not able to find an alternative statement for the same. Please help!

What is the difference between npm start and serve s build?

I know two way to deploy server is npm start and serve s build
So what different between npm start and serve s build to start server in react js?
These are all custom script, you can find the definition in package.json file. Normally start is for starting the development build, build is for making the production build.
Ex.
"scripts": {
"start": "react-scripts start",
"lint": "eslint ./src",
"lint:fix": "eslint ./src --fix",
"test": "react-scripts test",
"test:coverage": "react-scripts test --coverage --watchAll=false",
"build": "rollup -c",

React Material start script NODE_PATH not recognized

I have downloaded following React Material template
template
Followed steps from documentation
package.json
{
"name": "material-dashboard-react",
"version": "1.6.0",
"description": "Material Dashboard React. Coded by Creative Tim",
"private": false,
"main": "dist/index.js",
"scripts": {
"start": "NODE_PATH=./src react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
"lint:check": "eslint . --ext=js,jsx; exit 0",
"lint:fix": "eslint . --ext=js,jsx --fix; exit 0",
"build-package-css": "cp src/assets/css/material-dashboard-react.css dist/material-dashboard-react.css",
"build-package": "npm run build-package-css && babel src --out-dir dist"
},
}
Getting the following error
It is because you are using Windows. The project was likely ran on unix based computers before (NODE_PATH=./src is not a windows way of defining environment variables). You can either fix it by using the Windows syntax "start": "set NODE_PATH=./src react-scripts start", (your project will not run on unix machines) or use a cross-env library for defining your environment : https://www.npmjs.com/package/dotenv
For anyone wondering, I had the same issue with the same template and my solution was to configure a file in the project root as specified in this link.
I'm using docker and my working directory is in the /app directory, so I added this line in my tsconfig.json file at the root of my react app folder:
"compilerOptions": {
...,
"baseUrl": "/app/src",
}

Resources