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

TypeError: namingStrategy.tableName is not a function #8

Open
PaulMest opened this issue Sep 29, 2020 · 3 comments
Open

TypeError: namingStrategy.tableName is not a function #8

PaulMest opened this issue Sep 29, 2020 · 3 comments

Comments

@PaulMest
Copy link

If I upgrade TypeORM from 0.2.22 to 0.2.26 or 0.2.27 I get the following error:

[Nest] 8223   - 09/29/2020, 10:55:02 AM   [ExceptionHandler] Unable to connect to the database. Retrying (1)... +2531ms
TypeError: namingStrategy.tableName is not a function
    at EntityMetadata.build (/Users/paul/code/my-project/node_modules/typeorm/metadata/EntityMetadata.js:492:58)
    at /Users/paul/code/my-project/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:67:72
    at Array.forEach (<anonymous>)
    at EntityMetadataBuilder.build (/Users/paul/code/my-project/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:67:14)
    at ConnectionMetadataBuilder.buildEntityMetadatas (/Users/paul/code/my-project/node_modules/typeorm/connection/ConnectionMetadataBuilder.js:58:141)
    at Connection.buildMetadatas (/Users/paul/code/my-project/node_modules/typeorm/connection/Connection.js:515:57)
    at Connection.<anonymous> (/Users/paul/code/my-project/node_modules/typeorm/connection/Connection.js:128:30)
    at step (/Users/paul/code/my-project/node_modules/tslib/tslib.js:141:27)
    at Object.next (/Users/paul/code/my-project/node_modules/tslib/tslib.js:122:57)
    at fulfilled (/Users/paul/code/my-project/node_modules/tslib/tslib.js:112:62)

... any idea what could be the problem?

@tonivj5
Copy link
Owner

tonivj5 commented Sep 30, 2020

Hey, could you provide a reproduction repo?

I don't see where the error can come. tableName is defined in the strategy https://github.com/tonivj5/typeorm-naming-strategies/blob/master/src/snake-naming.strategy.ts#L10 and the strategy is setted into the connection https://github.com/typeorm/typeorm/blob/master/src/connection/Connection.ts#L130

@alii
Copy link

alii commented Jan 8, 2021

@PaulMest If you haven't resolved this, it also might be worth checking that you are emitting to es6+ with tsc. es5 and below has quirks with TypeScript and classes annoyingly. Has solved issues not too dissimilar before.

@ghdoergeloh
Copy link

I have the same issue.
At first I extended this class (we wanted to have the names in plural) and added the class to my project. everything worked fine.

But then I extracted the class into another package (symlinked via npm install ../path) and ran into this issue.

I thought it myght be a problem with my implementation or typescript configuration, so I downloaded the code and tried it with the repo-content. Still the same problem.

Then I tried to use the package tar from npmjs.com. First I put it next to my project and installed it with npm install ../typeorm-naming-strategies

  • test
    • src
      • index.ts
    • tsconfig.json
    • package.json
  • typeorm-naming-strategies

This created a symlink in test/node_modules.

When I tried to run my code the first time, it came up with this error:

Type 'SnakeNamingStrategy' is missing the following properties from type 'NamingStrategyInterface': closureJunctionTableName, primaryKeyName, uniqueConstraintName, relationConstraintName, and 10 more.

Then I installed the dependencies in typeorm-naming-strategies

The next Error was this:

TypeError: tableOrName.split is not a function
    at SnakeNamingStrategy.DefaultNamingStrategy.getTableName (./typeorm-naming-strategies/node_modules/typeorm/naming-strategy/DefaultNamingStrategy.js:20:28)
    at SnakeNamingStrategy.DefaultNamingStrategy.primaryKeyName (./typeorm-naming-strategies/node_modules/typeorm/naming-strategy/DefaultNamingStrategy.js:52:30)
    at PostgresQueryRunner.createTableSql (./test/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:2754:65)
    at PostgresQueryRunner.<anonymous> (./test/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:602:45)

When i deleted the symlink from node_modules and placed a copy of the tar content in node_modules everything worked fine again.

So I think it has something to do with symlinks and typescript and not really with this package, but if you have an idea why this issue occures, it would be very helpful. I think typescript needs to handle the dependencies relative to the folder, where the symlink is placed and not to where the original folder is, but I don't know how to tell typescript this.

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

4 participants