You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.5.3
Plugin version
5.2.0
Node.js version
16.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20.04
Description
I'm trying to deploy a Fastify app as a serverless function in Vercel. The function crashes when plugins are autoloaded but when they are individually loaded using fastify.register(), it runs fine. Stacktrace shows that packages from node_modules are not found:
2022-09-01T03:18:51.555Z 09a47476-218f-4551-a748-ff23511f5cb2 ERROR Unhandled Promise Rejection
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'fastify-plugin' imported from /var/task/src/plugins/sensible.js",
"reason": {
"errorType": "Error",
"errorMessage": "Cannot find package 'fastify-plugin' imported from /var/task/src/plugins/sensible.js",
"code": "ERR_MODULE_NOT_FOUND",
"stack": [
"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'fastify-plugin' imported from /var/task/src/plugins/sensible.js",
" at new NodeError (node:internal/errors:372:5)",
" at packageResolve (node:internal/modules/esm/resolve:954:9)",
" at moduleResolve (node:internal/modules/esm/resolve:1003:20)",
" at defaultResolve (node:internal/modules/esm/resolve:1218:11)",
" at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)",
" at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)",
" at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)",
" at link (node:internal/modules/esm/module_job:78:36)"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'fastify-plugin' imported from /var/task/src/plugins/sensible.js",
" at process.<anonymous> (file:///var/runtime/index.mjs:1131:17)",
" at process.emit (node:events:539:35)",
" at emit (node:internal/process/promises:140:20)",
" at processPromiseRejections (node:internal/process/promises:274:27)",
" at processTicksAndRejections (node:internal/process/task_queues:97:32)"
]
}
In the index, the package that was unsuccessfully imported was fastify-plugin but I also tried importing other npm packages on the plugin and had the same error. However, if the imported modules are from within the codebase, the error is not happening.
In contrast, I have verified that when plugins and routes are loaded via fastify.register(), the error is not observed and the function is running fine. See Steps to Reproduce section.
Additionally, I was able to verify that the node_modules folder exists in the root dir of the serverless environment.
Any leads on where to look at and how this can be fixed?
Steps to Reproduce
❌ To reproduce the crashing function when deployed in Vercel
Under the PR checks, click Show all checks and open the Details of the Vercel deployment check
Expected Behavior
Packages from node_modules when imported inside the autoloaded plugins and routes, just like how it is when the plugins are loaded via fastify.register()
The text was updated successfully, but these errors were encountered:
Are you using any kind of bundler to reduce deployment size? This library will not work if you use a bundler so you have to go back to manually registering each plugin instead
Prerequisites
Fastify version
4.5.3
Plugin version
5.2.0
Node.js version
16.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20.04
Description
I'm trying to deploy a Fastify app as a serverless function in Vercel. The function crashes when plugins are autoloaded but when they are individually loaded using
fastify.register()
, it runs fine. Stacktrace shows that packages from node_modules are not found:In the index, the package that was unsuccessfully imported was
fastify-plugin
but I also tried importing other npm packages on the plugin and had the same error. However, if the imported modules are from within the codebase, the error is not happening.In contrast, I have verified that when plugins and routes are loaded via
fastify.register()
, the error is not observed and the function is running fine. See Steps to Reproduce section.Additionally, I was able to verify that the
node_modules
folder exists in the root dir of the serverless environment.Any leads on where to look at and how this can be fixed?
Steps to Reproduce
❌ To reproduce the crashing function when deployed in Vercel
fastify-vercel-serverless
and click Import✅ To reproduce the successful deployment when plugins are autoloaded
Assuming the failing scenario above has been replicated:
Expected Behavior
Packages from node_modules when imported inside the autoloaded plugins and routes, just like how it is when the plugins are loaded via
fastify.register()
The text was updated successfully, but these errors were encountered: