Closed shubham-shar closed 3 years ago
Hi @shubham-shar , Please did you resolve this I am getting a similar error and after a couple of struggling I still did not get it. I get the below errors
s__nestjs_cqrs":"^6.1.0","COLORTERM":"truecolor","NODE_ENV":"production","VERSION":"1"}
debug: Starting Nest application...
debug: StatusModule dependencies initialized
debug: ConfigModule dependencies initialized
debug: TypeOrmModule dependencies initialized
debug: PassportModule dependencies initialized
debug: AuthModule dependencies initialized
debug: AppModule dependencies initialized
debug: CqrsModule dependencies initialized
debug: CommonModule dependencies initialized
error: Unable to connect to the database. Retrying (1)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (2)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (3)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (4)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (5)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (6)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (7)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (8)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Unable to connect to the database. Retrying (9)... {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"TypeOrmModule"}
error: Cannot use import statement outside a module {"trace":"/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/src/modules/domain/employees/entities/employee.entity.ts:1\nimport * as moment from 'moment-timezone';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (internal/modules/cjs/loader.js:1054:16)\n at Module._compile (internal/modules/cjs/loader.js:1102:27)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)\n at Module.load (internal/modules/cjs/loader.js:986:32)\n at Function.Module._load (internal/modules/cjs/loader.js:879:14)\n at Module.require (internal/modules/cjs/loader.js:1026:19)\n at require (internal/modules/cjs/helpers.js:72:18)\n at Function.PlatformTools.load (/Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/platform/PlatformTools.js:114:28)\n at /Users/harisu/Documents/github/Udacity/cdond-c3-projectstarter/backend/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69\n at Array.map (<anonymous>)","context":"ExceptionHandler"}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! glee2@1.0.0 start:prod: `node dist/main.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the glee2@1.0.0 start:prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/harisu/.npm/_logs/2020-08-07T18_03_32_593Z-debug.log
This is happening after using the command npm run start:prod
However when I run with npm run start:dev
i see the application listening on port 3030.
One other awkward thing is when I try to copy the dist folder which is what I am expected to deploy in the instance in AWS, I each time I run node main.js I get errors similar to the above and nothing seems to be working. This has prevented me from progressing with the CI/CD for deploying since the backend will not start.
I will appreciate any help if there is one. cc @Gaston-Udacity @bsommardahl @SarGould , Also if the instructions for clearly running the backend are included in the project instructions it will be great. I tried debugging and fixing the scripts provided to no avail.
@fanyui Have you had any luck ?, I am experiencing the same.
I installed node dependencies, built the package on the provisioned EC2 instance server,
then I have the following codes in a role of my ansible playbook:
- name: "use pm2 to run the node server"
shell: |
cd /home/ubuntu/backend
pm2 start npm -- run "start:dev"
and the backend server worked.
Thanks @zhulingchen , I will try that. However, this will mean the instructions should be edited since it specifically says you copy and run the compiled dist. Thanks again.
@shubham-shar
I finally figure it out, here is the way how it works using pm2
set the env variables (I did it in .bash_profile) _export ENVIRONMENT=production export TYPEORM_CONNECTION=postgres export TYPEORM_ENTITIES="./modules/domain/*/.entity*.{ts,js}" export TYPEORM_HOST=host export TYPEORM_PORT=5432 export TYPEORM_USERNAME=postgres export TYPEORM_PASSWORD=password export TYPEORM_DATABASE=udapeopleprod
cd backend
npm i
npm run build
cp package* ./dist
cd dist
npm i
we need this step to have all the dependencies
pm2 start main.js --update-env
look into the pm2 log to be sure if it's running: ~/.pm2/logs/main-out.log
For AWS EC2 server you only need to upload content of dist directory and package* files then you can start from step 7
Hello everyone in this discussion, Looks like the issue pertains to the local development and the steps you follow. If it is still an issue, feel free to reach out to our mentor network on the Knowledge hub.
Let me know if you want me to fix something in the starter code in this repo.
Thanks everyone.
Hi, I am trying to run the backend server locally, but it doesn't start the application instead I get below output
That is it, no Server is actually starting.
Steps to reproduce
npm i
npm run build
npm run start
I have tried below commands instead of
npm run start
too.