serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

Module not found error when building api route with email-templates

Open webbster-dev opened this issue 2 years ago • 1 comments

Issue Summary

Module not found error whenever building api route with email-templates import

Actual behavior

I have an API Route, which imports the Email Templates package. However when I build with serverless, I get an error Module not found for the package and it's dependencies. It builds fine with next build, what am I missing?

Expected behavior

I expect the project to build just fine, as it does too with next build.

Steps to reproduce

  • Create new project
  • Add api route, e.g. /api/contact
  • Install the email-templates package, yarn add email-templates
  • Import it in the api route.
  • build: serverless
  • See the error.

Screenshots/Code/Configuration/Logs

2s › myNextApplication › Error: Command failed with exit code 1: node_modules/.bin/next build
warn  - The `target` config is deprecated and will be removed in a future version.
See more info here https://nextjs.org/docs/messages/deprecated-target-config
warn  - SWC minify release candidate enabled. https://nextjs.org/docs/messages/swc-minify-enabled
Failed to compile.

./node_modules/consolidate/lib/consolidate.js
Module not found: Can't resolve 'velocityjs' in '/Users/thomas/development/projects/project/node_modules/consolidate/lib'

Import trace for requested module:
./node_modules/consolidate/index.js
./node_modules/email-templates/lib/index.js
./pages/api/contact.js
./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js?page=%2Fapi%2Fcontact&absolutePagePath=private-next-pages%2Fapi%2Fcontact.js&absoluteAppPath=private-next-pages%2F_app.jsx&absoluteAppServerPath=&absoluteDocumentPath=private-next-pages%2F_document.jsx&absoluteErrorPath=next%2Fdist%2Fpages%2F_error&absolute404Path=&distDir=private-dot-next&buildId=D015GPt_SMjjWTUz9wMFs&assetPrefix=&generateEtags=true&poweredByHeader=true&canonicalBase=&basePath=&runtimeConfig=&previewProps=%7B%22previewModeId%22%3A%22ac8be19e62da0609c224f5bd7039108a%22%2C%22previewModeSigningKey%22%3A%227426832f25b7886c98f329d22381d0a685d371337c320d42ee75b8643b3283f1%22%2C%22previewModeEncryptionKey%22%3A%224057a58165dcbdda5f9a31d4088951f729f6ee5d87fa0b69d1e0deea2990cff1%22%7D&loadedEnvFiles=W3sicGF0aCI6Ii5lbnYubG9jYWwiLCJjb250ZW50cyI6Ik5FWFRfUFVCTElDX01BUEJPWF9BQ0NFU1NfVE9LRU49cGsuZXlKMUlqb2lkMlZpWW5OMFpYSWlMQ0poSWpvaVkyd3dPRzFyZFdOa01EUjJOak5qYkdkNU9IRjBjMmhoYVNKOS5aQk5Rb00wYzZlWWV1NHNjWkk0MlV3XG5cbk1BSUxfSE9TVD1sb2NhbGhvc3Rcbk1BSUxfUE9SVD0xMDI1XG5NQUlMX1NFQ1VSRT1mYWxzZVxuTUFJTF9VU0VSPXJvb3Rcbk1BSUxfUEFTUz1zZWNyZXRcbk1BSUxfRlJPTT1cIlJCRyBTb2Z0d2FyZSA8bm9yZXBseUByYmdzb2Z0d2FyZS5ubD5cIlxuTUFJTF9UTz1cIlJpY2sgQnJ1bmtlbiA8cmlja0ByYmdzb2Z0d2FyZS5ubD5cIlxuIn0seyJwYXRoIjoiLmVudiIsImNvbnRlbnRzIjoiQVdTX0FDQ0VTU19LRVlfSUQ9QUtJQTQyWk9XNkc3UllDRVBYVVRcbkFXU19TRUNSRVRfQUNDRVNTX0tFWT1oeEdUeC8xV1EzcVN0M2FDUVRBSlVBSkpRc2ZxbUdsa2dKNDZDVy8zXG4ifV0%3D&i18n=&reactRoot=!

./node_modules/consolidate/lib/consolidate.js
Module not found: Can't resolve 'dustjs-linkedin' in '/Users/thomas/development/projects/project/node_modules/consolidate/lib'

Import trace for requested module:
./node_modules/consolidate/index.js
./node_modules/email-templates/lib/index.js
./pages/api/contact.js
./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js?page=%2Fapi%2Fcontact&absolutePagePath=private-next-pages%2Fapi%2Fcontact.js&absoluteAppPath=private-next-pages%2F_app.jsx&absoluteAppServerPath=&absoluteDocumentPath=private-next-pages%2F_document.jsx&absoluteErrorPath=next%2Fdist%2Fpages%2F_error&absolute404Path=&distDir=private-dot-next&buildId=D015GPt_SMjjWTUz9wMFs&assetPrefix=&generateEtags=true&poweredByHeader=true&canonicalBase=&basePath=&runtimeConfig=&previewProps=%7B%22previewModeId%22%3A%22ac8be19e62da0609c224f5bd7039108a%22%2C%22previewModeSigningKey%22%3A%227426832f25b7886c98f329d22381d0a685d371337c320d42ee75b8643b3283f1%22%2C%22previewModeEncryptionKey%22%3A%224057a58165dcbdda5f9a31d4088951f729f6ee5d87fa0b69d1e0deea2990cff1%22%7D&loadedEnvFiles=W3sicGF0aCI6Ii5lbnYubG9jYWwiLCJjb250ZW50cyI6Ik5FWFRfUFVCTElDX01BUEJPWF9BQ0NFU1NfVE9LRU49cGsuZXlKMUlqb2lkMlZpWW5OMFpYSWlMQ0poSWpvaVkyd3dPRzFyZFdOa01EUjJOak5qYkdkNU9IRjBjMmhoYVNKOS5aQk5Rb00wYzZlWWV1NHNjWkk0MlV3XG5cbk1BSUxfSE9TVD1sb2NhbGhvc3Rcbk1BSUxfUE9SVD0xMDI1XG5NQUlMX1NFQ1VSRT1mYWxzZVxuTUFJTF9VU0VSPXJvb3Rcbk1BSUxfUEFTUz1zZWNyZXRcbk1BSUxfRlJPTT1cIlJCRyBTb2Z0d2FyZSA8bm9yZXBseUByYmdzb2Z0d2FyZS5ubD5cIlxuTUFJTF9UTz1cIlJpY2sgQnJ1bmtlbiA8cmlja0ByYmdzb2Z0d2FyZS5ubD5cIlxuIn0seyJwYXRoIjoiLmVudiIsImNvbnRlbnRzIjoiQVdTX0FDQ0VTU19LRVlfSUQ9QUtJQTQyWk9XNkc3UllDRVBYVVRcbkFXU19TRUNSRVRfQUNDRVNTX0tFWT1oeEdUeC8xV1EzcVN0M2FDUVRBSlVBSkpRc2ZxbUdsa2dKNDZDVy8zXG4ifV0%3D&i18n=&reactRoot=!

./node_modules/consolidate/lib/consolidate.js
Module not found: Can't resolve 'atpl' in '/Users/thomas/development/projects/project/node_modules/consolidate/lib'

Import trace for requested module:
./node_modules/consolidate/index.js
./node_modules/email-templates/lib/index.js
./pages/api/contact.js
./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js?page=%2Fapi%2Fcontact&absolutePagePath=private-next-pages%2Fapi%2Fcontact.js&absoluteAppPath=private-next-pages%2F_app.jsx&absoluteAppServerPath=&absoluteDocumentPath=private-next-pages%2F_document.jsx&absoluteErrorPath=next%2Fdist%2Fpages%2F_error&absolute404Path=&distDir=private-dot-next&buildId=D015GPt_SMjjWTUz9wMFs&assetPrefix=&generateEtags=true&poweredByHeader=true&canonicalBase=&basePath=&runtimeConfig=&previewProps=%7B%22previewModeId%22%3A%22ac8be19e62da0609c224f5bd7039108a%22%2C%22previewModeSigningKey%22%3A%227426832f25b7886c98f329d22381d0a685d371337c320d42ee75b8643b3283f1%22%2C%22previewModeEncryptionKey%22%3A%224057a58165dcbdda5f9a31d4088951f729f6ee5d87fa0b69d1e0deea2990cff1%22%7D&loadedEnvFiles=W3sicGF0aCI6Ii5lbnYubG9jYWwiLCJjb250ZW50cyI6Ik5FWFRfUFVCTElDX01BUEJPWF9BQ0NFU1NfVE9LRU49cGsuZXlKMUlqb2lkMlZpWW5OMFpYSWlMQ0poSWpvaVkyd3dPRzFyZFdOa01EUjJOak5qYkdkNU9IRjBjMmhoYVNKOS5aQk5Rb00wYzZlWWV1NHNjWkk0MlV3XG5cbk1BSUxfSE9TVD1sb2NhbGhvc3Rcbk1BSUxfUE9SVD0xMDI1XG5NQUlMX1NFQ1VSRT1mYWxzZVxuTUFJTF9VU0VSPXJvb3Rcbk1BSUxfUEFTUz1zZWNyZXRcbk1BSUxfRlJPTT1cIlJCRyBTb2Z0d2FyZSA8bm9yZXBseUByYmdzb2Z0d2FyZS5ubD5cIlxuTUFJTF9UTz1cIlJpY2sgQnJ1bmtlbiA8cmlja0ByYmdzb2Z0d2FyZS5ubD5cIlxuIn0seyJwYXRoIjoiLmVudiIsImNvbnRlbnRzIjoiQVdTX0FDQ0VTU19LRVlfSUQ9QUtJQTQyWk9XNkc3UllDRVBYVVRcbkFXU19TRUNSRVRfQUNDRVNTX0tFWT1oeEdUeC8xV1EzcVN0M2FDUVRBSlVBSkpRc2ZxbUdsa2dKNDZDVy8zXG4ifV0%3D&i18n=&reactRoot=!

./node_modules/consolidate/lib/consolidate.js
Module not found: Can't resolve 'liquor' in '/Users/thomas/development/projects/project/node_modules/consolidate/lib'

Import trace for requested module:
./node_modules/consolidate/index.js
./node_modules/email-templates/lib/index.js
./pages/api/contact.js
./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js?page=%2Fapi%2Fcontact&absolutePagePath=private-next-pages%2Fapi%2Fcontact.js&absoluteAppPath=private-next-pages%2F_app.jsx&absoluteAppServerPath=&absoluteDocumentPath=private-next-pages%2F_document.jsx&absoluteErrorPath=next%2Fdist%2Fpages%2F_error&absolute404Path=&distDir=private-dot-next&buildId=D015GPt_SMjjWTUz9wMFs&assetPrefix=&generateEtags=true&poweredByHeader=true&canonicalBase=&basePath=&runtimeConfig=&previewProps=%7B%22previewModeId%22%3A%22ac8be19e62da0609c224f5bd7039108a%22%2C%22previewModeSigningKey%22%3A%227426832f25b7886c98f329d22381d0a685d371337c320d42ee75b8643b3283f1%22%2C%22previewModeEncryptionKey%22%3A%224057a58165dcbdda5f9a31d4088951f729f6ee5d87fa0b69d1e0deea2990cff1%22%7D&loadedEnvFiles=W3sicGF0aCI6Ii5lbnYubG9jYWwiLCJjb250ZW50cyI6Ik5FWFRfUFVCTElDX01BUEJPWF9BQ0NFU1NfVE9LRU49cGsuZXlKMUlqb2lkMlZpWW5OMFpYSWlMQ0poSWpvaVkyd3dPRzFyZFdOa01EUjJOak5qYkdkNU9IRjBjMmhoYVNKOS5aQk5Rb00wYzZlWWV1NHNjWkk0MlV3XG5cbk1BSUxfSE9TVD1sb2NhbGhvc3Rcbk1BSUxfUE9SVD0xMDI1XG5NQUlMX1NFQ1VSRT1mYWxzZVxuTUFJTF9VU0VSPXJvb3Rcbk1BSUxfUEFTUz1zZWNyZXRcbk1BSUxfRlJPTT1cIlJCRyBTb2Z0d2FyZSA8bm9yZXBseUByYmdzb2Z0d2FyZS5ubD5cIlxuTUFJTF9UTz1cIlJpY2sgQnJ1bmtlbiA8cmlja0ByYmdzb2Z0d2FyZS5ubD5cIlxuIn0seyJwYXRoIjoiLmVudiIsImNvbnRlbnRzIjoiQVdTX0FDQ0VTU19LRVlfSUQ9QUtJQTQyWk9XNkc3UllDRVBYVVRcbkFXU19TRUNSRVRfQUNDRVNTX0tFWT1oeEdUeC8xV1EzcVN0M2FDUVRBSlVBSkpRc2ZxbUdsa2dKNDZDVy8zXG4ifV0%3D&i18n=&reactRoot=!

./node_modules/consolidate/lib/consolidate.js
Module not found: Can't resolve 'twig' in '/Users/thomas/development/projects/project/node_modules/consolidate/lib'

Import trace for requested module:
./node_modules/consolidate/index.js
./node_modules/email-templates/lib/index.js
./pages/api/contact.js
./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js?page=%2Fapi%2Fcontact&absolutePagePath=private-next-pages%2Fapi%2Fcontact.js&absoluteAppPath=private-next-pages%2F_app.jsx&absoluteAppServerPath=&absoluteDocumentPath=private-next-pages%2F_document.jsx&absoluteErrorPath=next%2Fdist%2Fpages%2F_error&absolute404Path=&distDir=private-dot-next&buildId=LlErR0hjwpIl0qvl28-0Y&assetPrefix=&generateEtags=true&poweredByHeader=true&canonicalBase=&basePath=&runtimeConfig=&previewProps=%7B%22previewModeId%22%3A%2201a5462456fead02d8d4edb2a67f3e49%22%2C%22previewModeSigningKey%22%3A%22071f6b23148c0b7bde67b79094a24fe0373a453d46a6adf664a63701507ff3dc%22%2C%22previewModeEncryptionKey%22%3A%224800e4179968c8bd9a
info  - Loaded env from /Users/thomas/development/projects/project/.env.local
info  - Loaded env from /Users/thomas/development/projects/project/.env
info  - Checking validity of types...
info  - Creating an optimized production build...

Versions

  • OS/Environment: MacOS 12.0.1
  • @sls-next/serverless-component version: 3.8.0-alpha.0
  • Next.js version: 12.0.8

Additional context

When you comment out the import, everything works fine.

Checklist

  • [x] You have reviewed the README and FAQs, which answers several common questions.
  • [x] You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible. As there is only one maintainer (who maintains this in his free time) and thus very limited resources, if you have time, please try to debug the issue a bit yourself if possible.
  • [x] You have first tried using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

webbster-dev avatar Apr 27 '22 08:04 webbster-dev

This looks like an issue that several people have reported on the email-templates module (https://github.com/forwardemail/email-templates/issues/435) potentially relating to how the files have been bundled. Strangely people with various setups seem to be having the same issue, an intermediate solution might be some custom webpack config?

MGough avatar May 03 '22 09:05 MGough