question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use namespace 'Knex' as a type

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
RobMaplecommented, Apr 21, 2021

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.

0reactions
dafflcommented, Jul 13, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Objection 2.x does not support knex 0.95 · Issue #4389 - GitHub
d.ts(1382,12): error TS2709: Cannot use namespace 'Knex' as a type. [start:build] node_modules/objection/typings/ ...
Read more >
How to fix 'Cannot use namespace as a type ts(2709)' in ...
I was struggling to figure out how I could write a type definition for passing an external/3rd party module around.
Read more >
TypeScript / Node.js: Importing Knex into an ES6 module
js projects I've tried to move over to using ES6 modules in my server side code (away from CommonJS). That can cause challenges,...
Read more >
Fixing the "Cannot Use Namespace as a Type" Error in ...
Are you experiencing the “cannot use namespace as a type” error in TypeScript? This error can occur when you try to import types...
Read more >
[SOLVED] Cannot Use Namespace as a Type in TypeScript
Learn how to quickly fix the "cannot use namespace as a type" error in TypeScript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found