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

Error using knex module: Cannot find module './dialects/mysql/index.js' #79

Open
AntoineLep opened this issue May 24, 2019 · 4 comments

Comments

@AntoineLep
Copy link

AntoineLep commented May 24, 2019

Hello,

I have an error when trying to access my lambda function after it has been optimized.

I have tried to remove serverless-plugin-optimize and there is no problem (exept the package size which is 12Mb instead of 340Kb).
Here is the error I have when running sls invoke local --function myfunction):

{ Error: Cannot find module './dialects/mysql/index.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:613:15) at Function.Module._load (internal/modules/cjs/loader.js:539:25) at Module.require (internal/modules/cjs/loader.js:667:17) at require (internal/modules/cjs/helpers.js:20:18) ...

I'm using knex and it looks like this is the origin of the error.
After the code has been optimized I can see the following in handler.js

Dialect=require(./dialects/${resolvedClientName}/index.js)}

This code is normally part of node_module/knex/knex.js file.

${resolvedClientName} is filled at the execution with my database engine name. i.e. mysql.
But the local path ./dialects/${resolvedClientName}/index.js doesn't exists anymore since it has been optimized and there is no node_module/knex/{any_knex_tree_folder}

Is there a way to include it in optimized package ?

@j-petty
Copy link

j-petty commented Aug 26, 2019

I'm having the same issue. Did you manage to find a solution for this @AntoineLep?

@AntoineLep
Copy link
Author

A dirty solution is to fork the project, then to hardcode the ${resolvedClientName} var with your db client and to rebuild it as a local npm package.

I finally did without knex since that was not a reliable solution for a professional project due to this issue when combined with serverless-plugin-optimize.

@j-petty
Copy link

j-petty commented Mar 2, 2020

Bumping this issue as the workaround isn't a solution.

@suryacaprice
Copy link

anyone have a solution for it?

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

3 participants