I'm encountering build errors with a next.js app on AWS Amplify while it builds and runs fine on my local machine. Specifically, it seems that webpack is trying to include all of the various SQL packages that knex might use. The error message is
Can't resolve 'tedious'
Since I am only connecting to a mysql server and have explicitly listed mysql2 in package.json, I don't need the tedious module as it appears to be for MS SQL Server. Adding tedious to package.json causes the build to complain about mssql, which is yet another module I don't actually need.
Based on this github knex issue, a workaround appears to be adding the various modules to the webpack externals config. The next.js custom webpack config documentation indicates that such settings should be in the next.config.js file. However, I can't seem to get the correct combination. Here is my next.config.js file:
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.externals.concat([
// Possible drivers (and related modules) for knex - we'll ignore them
'tedious',
'mssql',
// etc. with more modules
]);
return config;
},
}
Unfortunately the error persists.