Can't init TypeORM project

Viewed 1629

I'm trying to create a new TypeORM project and have run the following commands, according to the TypeORM documentation:

npm install typeorm -g

typeorm init --name MyProject --database postgres

I get this error:

TypeError: Cannot set property EntityManager of #<Object> which has only a getter
at Object.<anonymous> (~/.npm-global/lib/node_modules/typeorm/index.js:120:23)
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)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (~/.npm-global/lib/node_modules/typeorm/commands/SchemaSyncCommand.js:4:15)
at Module._compile (internal/modules/cjs/loader.js:778:30)

I get the same error even if I just try to run

typeorm
4 Answers

Add

"resolutions": { 
    "tslib": "1.11.2"
}

to your package json, tslib 1.12 breaks typeorm

The workaround that did it for me was this:

npm i tslib@1.11.2 --save and remove the ^ before the version in package.json of my project.

The open issue can be found here

Ok, there's apparently an issue with one of the dependencies used by TypeORM. The dependency tslib 1.12.0 apparently breaks TypeORM. If you've installed TypeORM globally, go to your install folder (default is probably /usr/local/lib/node_modules/typeorm) and edit the package.json file. Change the version of tslib to "1.11.2". Then run npm update to update the dependencies.

In my case I was facing the same problem and I've created a file called ormconfig.json at the project's root with my credentials.

{
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "postgres",
  "password": "pass",
  "database": "database_name"
}

After that the problem is no more.

Before I had tried the user840250's solution. It worked for the original problem but it had created another one: UnhandledPromiseRejectionWarning: Error: No connection options were found in any of configurations file.

Related