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 read property 'QueryBuilder' of undefined

See original GitHub issue

Compiling and running a simple typescript example results in TypeError: Cannot read property 'QueryBuilder' of undefined.

Environment

Knex version: 0.95.0 Node version: 14.16.0 Typescript version: 4.2.3

Steps to reproduce:

$ yarn init -y
$ yarn add typescript knex @types/node
$ tsc --init

Create a test.ts file with:

import {Knex} from 'knex'
console.log(Knex.QueryBuilder)

Then

$ tsc test.ts
$ node test.js

This yields the following error:

console.log(knex_1.Knex.QueryBuilder);
                        ^

TypeError: Cannot read property 'QueryBuilder' of undefined
    at Object.<anonymous> (/xxx/test.js:4:25)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

The Knex variable is not exported from the package, only knex. A simple fix could be to just add knex.Knex = knex to knex.js ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
kibertoadcommented, Mar 11, 2021

@gudleik 0.95.0 with the fix released!

1reaction
kibertoadcommented, Mar 7, 2021

That does sounds like a problem with our types. I’ll take a look tomorrow. Code itself should work, I think we just miss a type there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'tablePivot ...
I'm trying to make a query builder with cubejs. I followed their documentation and copied the code of their sandbox here ...
Read more >
TypeError: Cannot read property 'operator' of undefined #80
Hi,. When change the operator in material theme, throw "TypeError: Cannot read property 'operator' of undefined" . You can see demo material ...
Read more >
Query Builder JavaScript error Uncaught TypeError
When I click on Export CSV I get this error in the console. I get this in Chrome and Edge. Firefox won't load...
Read more >
typeorm cannot read properties of undefined
What happens in your case is typeorm is creating an instance of the entity and is not passing anything in the constructor. So...
Read more >
Cannot read properties of undefined (reading 'id')
This error can be thrown for a lot of reasons, as it is not uncommon to look for the id property of an...
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