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

Cannot use namespace 'Knex' as a type #259

Closed
SeveHo opened this issue Apr 19, 2021 · 5 comments
Closed

Cannot use namespace 'Knex' as a type #259

SeveHo opened this issue Apr 19, 2021 · 5 comments

Comments

@SeveHo
Copy link

SeveHo commented Apr 19, 2021

Steps to reproduce

  1. Generated a clean app with TypeScript enabled
    feathers generate app

  2. Generate a new service with
    feathers generate service and choose KnexJS as service type

Expected behavior

When starting the app (nom start) tsc should compile successfully.

Actual behavior

Lots of errors about Knex namespace. E.g:

node_modules/feathers-knex/types/index.d.ts:22:10 - error TS2709: Cannot use namespace 'Knex' as a type.

22   Model: Knex;
            ~~~~

src/models/users.model.ts:8:45 - error TS2709: Cannot use namespace 'Knex' as a type.

8 export default function (app: Application): Knex {
                                              ~~~~

System configuration

Module versions (especially the part that's not working):

    "@feathersjs/authentication": "^4.5.11",
    "@feathersjs/authentication-local": "^4.5.11",
    "@feathersjs/authentication-oauth": "^4.5.11",
    "@feathersjs/configuration": "^4.5.11",
    "@feathersjs/errors": "^4.5.11",
    "@feathersjs/express": "^4.5.11",
    "@feathersjs/feathers": "^4.5.11",
    "@feathersjs/socketio": "^4.5.11",
    "@feathersjs/transport-commons": "^4.5.11",
    "@types/multer": "^1.4.5",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "dauria": "^2.0.0",
    "feathers-knex": "^7.1.1",
    "helmet": "^4.4.1",
    "knex": "^0.95.4",
    "multer": "^1.4.2",
    "multer-ovh-objectstorage": "^2.0.0",
    "pg": "^8.5.1",
    "serve-favicon": "^2.5.0",
    "winston": "^3.3.3"
  },
  "devDependencies": {
    "@types/compression": "^1.7.0",
    "@types/cors": "^2.8.10",
    "@types/jest": "^26.0.22",
    "@types/jsonwebtoken": "^8.5.1",
    "@types/serve-favicon": "^2.5.2",
    "@typescript-eslint/eslint-plugin": "^4.21.0",
    "@typescript-eslint/parser": "^4.21.0",
    "axios": "^0.21.1",
    "eslint": "^7.24.0",
    "jest": "^26.6.3",
    "prettier": "^2.2.1",
    "shx": "^0.3.3",
    "ts-jest": "^26.5.4",
    "ts-node-dev": "^1.1.6",
    "typescript": "^4.2.4"
  }

NodeJS version:
15.14.0

Operating System:
macOS Big Sur 11.2

@RobMaple
Copy link

I had the same issue using the Objection driver which also utilises Knex. To fix it you should just need to change the import statement in src/models/users.model.ts from import Knex from 'knex'; to import {Knex} from 'knex';.

Of course this doesn't change whats created via the CLI but should allow it all to compile in the meantime.

@jordanmsllvn
Copy link

jordanmsllvn commented May 4, 2021

This seems to be an issue with the feathers-knex library as well. Not only the generator's output.
I get these errors when compiling:

node_modules/feathers-knex/types/index.d.ts:8:10 - error TS2709: Cannot use namespace 'Knex' as a type.

8   Model: Knex;
           ~~~~

node_modules/feathers-knex/types/index.d.ts:15:64 - error TS2709: Cannot use namespace 'Knex' as a type.

15     function start(options?: { getKnex: (hook: HookContext) => Knex | undefined }): Hook;
                                                                  ~~~~

node_modules/feathers-knex/types/index.d.ts:22:10 - error TS2709: Cannot use namespace 'Knex' as a type.

22   Model: Knex;
            ~~~~

node_modules/feathers-knex/types/index.d.ts:23:9 - error TS2709: Cannot use namespace 'Knex' as a type.

23   knex: Knex;
           ~~~~

node_modules/feathers-knex/types/index.d.ts:29:24 - error TS2709: Cannot use namespace 'Knex' as a type.

29   db(params?: Params): Knex;
                          ~~~~

node_modules/feathers-knex/types/index.d.ts:31:33 - error TS2709: Cannot use namespace 'Knex' as a type.

31   createQuery(params?: Params): Knex;
                                   ~~~~

Downgrading to a pre 0.95.0 version of Knex solves the issue.

@joezappie
Copy link

joezappie commented May 8, 2021

I am also having this issue.

cbeninati added a commit to cbeninati/feathers-knex that referenced this issue Jul 1, 2021
@ShinChven
Copy link

Temperary solution:

Edit tsconfig.json

{
  "compilerOptions": {
    "skipLibCheck": true
  }
}

daffl pushed a commit that referenced this issue Jul 13, 2021
Update Knex type definition import for 0.95.x.

#259

Reference: https://github.com/knex/knex/blob/master/UPGRADING.md
@daffl
Copy link
Member

daffl commented Jul 13, 2021

Closed via #262

@daffl daffl closed this as completed Jul 13, 2021
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

6 participants