Search code examples
node.jsnestjstypeorm

TypeORM + TypeError: Cannot set property EntityManager of #<Object> which has only a getter


I have a Nest application which is not starting due to the following exception. I am not sure what is the cause of the problem.

I created this GitHub repository to replicate the issue. The running instructions are detailed in the README.

The error:

TypeError: Cannot set property EntityManager of #<Object> which has only a getter
    at Object.<anonymous> (/Users/saulo/NodeProjects/typeorm-jest-issues/node_modules/typeorm/index.js:120:23)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/saulo/NodeProjects/typeorm-jest-issues/node_modules/@nestjs/typeorm/dist/common/typeorm.utils.js:5:19)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)

Solution

  • There seems to be an issue with the tslib dependency. You can find more info here:

    https://github.com/typeorm/typeorm/issues/6054

    But a temporary solution to start your project is to add [email protected] as a dependency (yarn add [email protected]) and to add this to your package.json

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