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.

Any way to use `knex`?

See original GitHub issue

Currently trying to package knex with pg. This was also a problem serverless-webpack faced but by force including the required packages it worked in the end. This is the only issue that I could find related to knex and esbuild but doesn’t seem to solve my problem.

This is the error I get when running sls package:

# ...

Serverless: Packing external modules: knex@^0.95.4, mysql, mysql2, pg@^8.6.0, pg-native, sqlite3, tedious

Error ---------------------------------------------------
 
Error: npm install failed with code 1
   at ChildProcess.<anonymous> (/home/arpad/workspace/sls-webpack-v-esbuild/esbuild/node_modules/serverless-esbuild/dist/utils.js:48:24)
   at ChildProcess.emit (events.js:314:20)
   at ChildProcess.EventEmitter.emit (domain.js:483:12)
   at maybeClose (internal/child_process.js:1022:16)
   at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)

# ...

To note that it also tries to include mysql, mysql2, pg-native, sqlite3 and tedious and I’m not sure how I can ignore them.

And this is my config:

// ...

custom: {
  esbuild: {
    bundle: true,
    minify: false,
    external: ['knex', 'pg'],
  },
},

package: {
  individually: true,
},

// ...

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
arpadgaborcommented, Apr 14, 2021

Yep, now it’s working perfectly!

Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Compiling with esbuild...
Serverless: Compiling completed.
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: knex@^0.95.4, pg@^8.6.0
Serverless: Zip function: esbuild-testing-zone-dev-create - 27.95 KB [74 ms]
Serverless: Zip function: esbuild-testing-zone-dev-findById - 27.98 KB [59 ms]
Serverless: Zip function: esbuild-testing-zone-dev-find - 1.14 MB [612 ms]
Serverless: Packaging service...

Thanks a lot! Looking forward to an update with the PR and this will be great.

1reaction
olupcommented, Apr 14, 2021

Oh sorry of course, it needs deps install and building in the node modules - you cannot try it just like that - my bad. Anyway I am pretty sure it fixes your problems. I’ll add exclude anyways to the mix and let’s wait for @floydspace’s input on the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Knex.js Tutorial For Beginners - Shahed Nasser
In this tutorial, you'll learn how to use Knex.js with Node.js and Express. We'll create migrations, seeders, then query and insert data ...
Read more >
Knex.js: SQL Query Builder for Javascript
Knex.js is a "batteries included" SQL query builder for PostgreSQL, CockroachDB, MSSQL, MySQL, MariaDB, SQLite3, Better-SQLite3, Oracle, and Amazon Redshift ...
Read more >
Knex.Js. Beginner's Guide in Examples | LITSLINK | - Medium
1. Create a package.json file in your project folder and copy-paste these lines: Run npm install in your project folder. · 2. Create...
Read more >
Knex.js tutorial - programming databases with Knex.js - ZetCode
Knex.js is a JavaScript query builder for relational databases including PostgreSQL, MySQL, SQLite3, and Oracle. It can be used with callbacks ...
Read more >
Use SQL Query Builder Knex.js with Node.js and Express.js
Step 1. Install Knex.js and migration CLI · Step 2. Database configuration · Step 3. Migrate using migration CLI · Step 4. Define...
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