Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm run start:prod error #18

Open
Darcy-shinet opened this issue Jun 9, 2019 · 3 comments
Open

npm run start:prod error #18

Darcy-shinet opened this issue Jun 9, 2019 · 3 comments

Comments

@Darcy-shinet
Copy link

I want to start prod this following error.
[Nest] 92672 - 2019-06-09 09:49 [NestFactory] Starting Nest application...
[Nest] 92672 - 2019-06-09 09:49 [InstanceLoader] TypeOrmModule dependencies initialized +131ms
[Nest] 92672 - 2019-06-09 09:49 [TypeOrmModule] Unable to connect to the database. Retrying (1)... +105ms
/Users/lee/Sites/demo/nestjs-realworld-example-app/src/article/article.entity.ts:1
(function (exports, require, module, __filename, __dirname) { import { Entity, PrimaryGeneratedColumn, Column, OneToOne, ManyToOne, OneToMany, JoinColumn, AfterUpdate, BeforeUpdate } from 'typeorm';
^^^^^^

SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Function.PlatformTools.load (/Users/lee/Sites/demo/nestjs-realworld-example-app/node_modules/_typeorm@0.2.18@typeorm/platform/PlatformTools.js:107:28)
[Nest] 92672 - 2019-06-09 09:49 [TypeOrmModule] Unable to connect to the database. Retrying (2)... +3025ms
/Users/lee/Sites/demo/nestjs-realworld-example-app/src/article/article.entity.ts:1
(function (exports, require, module, __filename, __dirname) { import { Entity, PrimaryGeneratedColumn, Column, OneToOne, ManyToOne, OneToMany, JoinColumn, AfterUpdate, BeforeUpdate } from 'typeorm';

@ilyasfoo
Copy link

Try this:

In package.json modify npm scripts to include NODE_ENV environment variable

{
...
  "scripts": {
    "start": "NODE_ENV=development node index.js",
    "start:watch": "NODE_ENV=development nodemon",
    "start:prod": "NODE_ENV=production node dist/src/main.js",
   }
...
}

Change ormconfig.json to ormconfig.js and do something similar to the following. Note the entities now loads either .js or .ts according to environment.

module.exports = {
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "username": "...",
  "password": "...",
  "database": "...",
  "entities": [ process.env.NODE_ENV == 'production' ? __dirname + '/dist/src/**/**.entity.js' : __dirname + '/src/**/**.entity.ts' ],
  "migrationsTableName": "migrations",
  "migrations": ["database/migration/*.js"],
	"cli": {
	    "migrationsDir": "database/migration"
	},
  "synchronize": true
}

@eating-noodles
Copy link

+1 any else answers?

@eating-noodles
Copy link

Try this:

In package.json modify npm scripts to include NODE_ENV environment variable

{
...
  "scripts": {
    "start": "NODE_ENV=development node index.js",
    "start:watch": "NODE_ENV=development nodemon",
    "start:prod": "NODE_ENV=production node dist/src/main.js",
   }
...
}

Change ormconfig.json to ormconfig.js and do something similar to the following. Note the entities now loads either .js or .ts according to environment.

module.exports = {
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "username": "...",
  "password": "...",
  "database": "...",
  "entities": [ process.env.NODE_ENV == 'production' ? __dirname + '/dist/src/**/**.entity.js' : __dirname + '/src/**/**.entity.ts' ],
  "migrationsTableName": "migrations",
  "migrations": ["database/migration/*.js"],
	"cli": {
	    "migrationsDir": "database/migration"
	},
  "synchronize": true
}

it works.Just remember to modify the workspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants