Gabriel Gordon-Hall
06/17/2021, 7:39 PMsst start
, but when I run sst deploy
I get the following error:
2021-06-17T19:18:15.874Z undefined ERROR Uncaught Exception {
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module '../../dialects/postgres/index.js'\nRequire stack:\n- /var/task/invoke.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module '../../dialects/postgres/index.js'",
"Require stack:",
"- /var/task/invoke.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object.<anonymous> (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:999:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
" at Module.load (internal/modules/cjs/loader.js:863:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
" at internal/main/run_main_module.js:17:47"
]
}
It’s odd because I can see knex/lib/dialects/postgres/index.js
in my node modules folder. I also have pg installed. I have tried explicitly importing pg in my lambda but to no avail.
Here’s the lambda code:
import Knex from "knex";
const pgEnv = process.env.POSTGRES || "";
const config = {
client: "pg",
connection: pgEnv,
};
const knex = Knex(config);
I found a webpack workaround for this error is to add the following to the `webpack.config.js`:
module.exports = {
entry: slsw.lib.entries,
target: "node",
externals: { knex: "commonjs knex" },
};
Is there a similar workaround that would be compatible with SST?
Thanks!Ross Coundon
06/17/2021, 7:41 PMGabriel Gordon-Hall
06/17/2021, 9:17 PMError: Cannot find module 'knex'
Sorry if I’m missing something glaringly obvious.Ross Coundon
06/17/2021, 9:39 PMthdxr
06/17/2021, 10:29 PMthdxr
06/17/2021, 10:29 PMthdxr
06/17/2021, 10:30 PMRoss Coundon
06/18/2021, 6:45 AMGabriel Gordon-Hall
06/18/2021, 7:58 AMColin Cheung
11/03/2021, 6:01 PM