r/webpack • u/NovelVeterinarian246 • Feb 18 '24
Webpack and Node Modules
I'm trying to configure my Serverless Typescript project to use Webpack. Running serverless webpack works without issue, but when I deploy my bundled code to AWS, I run into problems with my node modules. When I try to hit any of my endpoints, I get errors like this :
"errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'jwt-decode'The above example shows jwt-decode being not found, but the same error occurs for all external modules I import. When I look at the code bundles serverless deploys, it is true that they don't contain any node_modules with them. I believe this is because I have externals: [nodeExternals()] set in my webpack.config.js file. I can overwrite this by updating the serverless-webpack plugin configuration in my serverless.yml file like so:
webpack:
includeModules: trueBut in trying to research this I've found resources (such as this one) saying that you actually don't want to use webpack to bundle related node modules in with your code.
Is it true that I shouldn't be bundling node modules? And, if so, how is my code supposed to reference these external packages when deployed?
Thanks in advance for the help
View all comments
Show parent comment
1
u/NovelVeterinarian246 Feb 18 '24
Thank you for the response. I'm trying to optimize for scalability. The API that I am building is currently small, but in theory it could grow to a decent size over time. Would using a layer to hold my node modules be best in this case? Also, I'm not married to webpack, I'd be interested to know why you switched to esbuild if you don't mind sharing!