Funny, I tried to use esbuild for the functions as @hrishikesh suggested on the other thread
netlify.toml
[build]
command = "npm run build"
publish = "out"
[functions]
node_bundler = "esbuild"
And now I get some extra error messages:
9:12:32 AM: ────────────────────────────────────────────────────────────────
9:12:32 AM: 4. Functions bundling
9:12:32 AM: ────────────────────────────────────────────────────────────────
9:12:32 AM:
9:12:33 AM: Packaging Functions from .netlify/functions-internal directory:
9:12:33 AM: - next_image/next_image.js
9:12:33 AM: - next_videos/next_videos.js
9:12:33 AM: - next_videos_videoId/next_videos_videoId.js
9:12:33 AM:
9:12:33 AM: > .netlify/functions-internal/next_videos/nextPage/pages/videos.js:253:25: error: Could not resolve "mysql2" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 253 │ module.exports = require("mysql2");
9:12:33 AM: ╵ ~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos_videoId/nextPage/pages/videos/[videoId].js:373:25: error: Could not resolve "mysql2" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 373 │ module.exports = require("mysql2");
9:12:33 AM: ╵ ~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos/nextPage/pages/videos.js:277:25: error: Could not resolve "oracledb" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 277 │ module.exports = require("oracledb");
9:12:33 AM: ╵ ~~~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos_videoId/nextPage/pages/videos/[videoId].js:394:25: error: Could not resolve "oracledb" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 394 │ module.exports = require("oracledb");
9:12:33 AM: ╵ ~~~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos/nextPage/pages/videos.js:301:25: error: Could not resolve "pg" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 301 │ module.exports = require("pg");
9:12:33 AM: ╵ ~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos_videoId/nextPage/pages/videos/[videoId].js:415:25: error: Could not resolve "pg" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 415 │ module.exports = require("pg");
9:12:33 AM: ╵ ~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos/nextPage/pages/videos.js:309:25: error: Could not resolve "pg-query-stream" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 309 │ module.exports = require("pg-query-stream");
9:12:33 AM: ╵ ~~~~~~~~~~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos_videoId/nextPage/pages/videos/[videoId].js:422:25: error: Could not resolve "pg-query-stream" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 422 │ module.exports = require("pg-query-stream");
9:12:33 AM: ╵ ~~~~~~~~~~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos/nextPage/pages/videos.js:325:25: error: Could not resolve "sqlite3" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 325 │ module.exports = require("sqlite3");
9:12:33 AM: ╵ ~~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos_videoId/nextPage/pages/videos/[videoId].js:436:25: error: Could not resolve "sqlite3" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 436 │ module.exports = require("sqlite3");
9:12:33 AM: ╵ ~~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos/nextPage/pages/videos.js:349:25: error: Could not resolve "tedious" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 349 │ module.exports = require("tedious");
9:12:33 AM: ╵ ~~~~~~~~~
9:12:33 AM: > .netlify/functions-internal/next_videos_videoId/nextPage/pages/videos/[videoId].js:457:25: error: Could not resolve "tedious" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
9:12:33 AM: 457 │ module.exports = require("tedious");
9:12:33 AM: ╵ ~~~~~~~~~
9:12:34 AM:
9:12:34 AM: ────────────────────────────────────────────────────────────────
9:12:34 AM: Internal error during "Functions bundling"
9:12:34 AM: ────────────────────────────────────────────────────────────────
9:12:34 AM:
9:12:34 AM: Error message
9:12:34 AM: Error: readdirp: root argument is required. Usage: readdirp(root, options)
9:12:34 AM:
9:12:34 AM: Error location
9:12:34 AM: During Functions bundling
9:12:34 AM: at readdirp (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:262:11)
9:12:34 AM: at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:276:5
9:12:34 AM: at new Promise (<anonymous>)
9:12:34 AM: at Function.readdirpPromise [as promise] (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:274:10)
9:12:34 AM: at hasFunctionRootFile (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:119:32)
9:12:34 AM: at lacksNodeModules (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:111:12)
9:12:34 AM: at getModuleNotFoundMessage (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:50:43)
9:12:34 AM: at getModuleNotFoundErrorObject (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:41:25)
9:12:34 AM: at getModuleNotFoundErrorFromEsbuild (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:81:10)
9:12:34 AM: at getModuleNotFoundError (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:33:34)
Which makes no sense because I already had that issue on my local environment and it seemed to solve when I did what it suggests on my next.config.js
:
module.exports = {
reactStrictMode: true,
target: "serverless", // Apparently this is required by Netlify
webpack5: true,
webpack: (config, { webpack, isServer}) => {
config.externals = config.externals.concat([
'mssql', 'mysql2', 'oracle', 'oracledb', 'postgres', 'redshift', 'sqlite3', 'pg', 'pg-query-stream', 'tedious']);
return config;
},
}