-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Should load MySQL, tries to load mssql #2860
Comments
That's highly improbable, given that code for resolving dialect is
and there is no alias for mssql. |
@NicoAiko Could you upload entire project in a zipfile somewhere? I'm pretty sure this has to work. |
I can make a repository for it, one sec |
Here's the repo: https://github.com/NicoAiko/typescript-knex-error EDIT: |
does it try to load mssql also if you try to use postgresql or sqlite? This could be related to a fact that knex monkeypatches mssql internally... maybe those requires are leaked by accident somewhere. |
Changed it to const knex = Knex({
client: 'sqlite3',
connection: { filename: './db.sqlite' },
}); Same as before: Tries to load mssql. |
Does CRA bundle all the code somehow? That could be one reason why it fails (there would be other errors too from other dialects though) |
It appears that transpilation is to blame, as error is not thrown from inside the knex. I think what happens is that you attempt to resolve all imports from within all dependencies, and since dialects attempt to import their drivers, that fails. |
So, what to do? |
The same also happens with sequelize, it seems. I try to load the mysql dialect and it wants to require Is that only on my machine? What am I doing wrong? |
@NicoAiko Considering that it seems to be failing during bundling phase, can you try disabling bundling and see if that helps? |
I see that node_modules are excluded in TS configuration, so it's likely to be a Webpack thing. |
Oof... I have to look into that actually. I have no custom webpack config. |
Yeah, so probably easiest way would be to eject config and see what's inside. Could be that default webpack config bundles way too aggressively, you may need additional excludes there. |
Would you be able to tell me what might be wrong? Because I don't really know. |
I have the webpack config on the master branch in my repo that I linked above. |
@nickwhiteley Why are you bundling a backend dependency inside of a frontend application anyway, though? |
It's a test project on what I can do with typescript. It doesn't matter that much if there is the database stuff in the react-project. I just want to try things out. |
And I'm not Nick Whiteley :D |
Sorry :D. |
Seems about right ^^' |
It is, but I don't think it could be resolved from knex side gracefully, unfortunately. |
I close this issue as the transfer to a backend project really solved it. |
I'm having the same issue. There's some recent changes going on with webpack that breaks things. Can't pinpoint it though. Mine's in an electron project so I can't really separate the two. |
@burningTyger Why do you need webpack on backend application, though? |
@kibertoad I edited my comment. It's an electron app. |
@burningTyger OK, that's actually a legitimate use-case. Please let me know if you will find either a configuration solution from your side or figure out what knex could be doing differently to avoid breaking stuff - so that we could improve either our documentation or implementation. |
Can we move this to gitter? I posted an error log some time ago to which you answered |
moving stuff to the main thread helped a lot |
I'm also doing a electron-react app my knex is having the same problem. TELL ME WHAT YOU DISCOVERED |
Put your knex queries into the main thread. Don't use the renderer for knex stuff. Only communicate via IPC from main to renderer. Then you should be good. I noticed using the dB drivers directly also works from the renderer and is a lot more lightweight. |
you're awesome!! |
I have this issue with angular universal. |
@kibertoad I have a one off application https://github.com/michaelavila/knex-querylab that I found useful when I was writing a lot of knex, and I've tried to keep it online over the years in case others find it useful. This site is made to let you quickly tinker with the knex dsl. All of the work is done in the browser. I could pass the input off to a server to translate and send back to me, but that would mean I'd need to put together and deploy some server. Right now, this is able to all run in browser and I can host it cheaply and easily on github pages. So, I don't want to go down that other route. Here are a few thoughts I have:
I'm sure I'm missing something and there are likely better alternatives than mine, but there you have it. |
@michaelavila But knex is already doing that, all drivers are lazy-loaded when first used, which is why most applications work just fine with just a subset of drivers. The only case where all drivers are loaded eagerly is when using a misconfigured webpack. Note that Please let me know if that helps. |
@kibertoad I'll dig into that now, thanks! |
Environment
Knex version: 0.15.2
Database + version: MariaDB v10.3
OS: macOS Mojave (v10.14)
Typescript: v3.1.1
Bug
Expected behaviour:
Should load the MySQL dialect.
Actual behaviour
Tries to load the mssql dialect.
Error Message:
"Module not found: Can't resolve 'mssql/package.json' in 'XYZ/node_modules/knex/lib/dialects/mssql'
My code:
The text was updated successfully, but these errors were encountered: