Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v8.2.1 requires custom config when used with serverless-esbuild #349

Closed
r-token opened this issue Dec 29, 2023 · 7 comments
Closed

v8.2.1 requires custom config when used with serverless-esbuild #349

r-token opened this issue Dec 29, 2023 · 7 comments
Labels

Comments

@r-token
Copy link

r-token commented Dec 29, 2023

After upgrading from v8.1.0 and attempting a deploy, I get an error saying the following:

Error: Compilation failed for function alias warmUpPluginDefault. Please ensure you have an index file with ext .ts or .js, or have a path listed as main key in package.json

Version 8.1.0 compiles and deploys successfully, but 8.2.1 and 8.3.0 both return this error and fail to deploy.

I need to use one of these newer versions as AWS is end-of-lifeing Node 16 in June.

@juanjoDiaz
Copy link
Owner

Hi @r-token ,

I need more details about your setup.
Specifically, about other plugins that you are using.

The issue that you are getting is because you are using a plugin to compile to your code (I assume that from Typescript) and it's trying to compile the warmup lambda.

The order in which you declare the plugins matters.
Have you tried declaring the warmup plugin after the compilation plugin?

@r-token
Copy link
Author

r-token commented Jan 2, 2024

Hey @juanjoDiaz, great info - I'm sure you are correct. I am using serverless-esbuild, though declaring the warmup plugin after esbuild did not resolve the issue.

serverless-esbuild allows you to exclude files from its build step. Where is that warmUpPluginDefault declared? Hopefully I can just exclude that file and that will resolve it.

@r-token
Copy link
Author

r-token commented Jan 2, 2024

@juanjoDiaz I was able to resolve this with the following steps:

  1. Add a custom esbuild config file that supports mjs file extensions. By default only js and ts are supported.

That fixed the initial error and it could compile that file properly, but I was then getting an error saying .warmup/default/index.mjs:4:44: ERROR: Could not resolve "@aws-sdk/client-lambda".

So step two was:

  1. Install @aws-sdk/client-lambda as a dev dependency.

I was then able to deploy successfully with v8.3.0.

Thank you for the help here! If this is an acceptable resolution then I think we can consider this issue closed.

@juanjoDiaz juanjoDiaz changed the title Compilation failures on v8.2.1 and later v8.2.1 requires custom config when used with serverless-esbuild Jan 11, 2024
@ElChapitan
Copy link

Hey @r-token , just ran into this problem myself. Any chance you can share some of the config setup you needed to make in order to get it to run?

@ElChapitan
Copy link

For those coming to this later and needing some more info:

I added an esbuild.config.js with this:

module.exports = () => ({
  external: [],
  resolveExtensions: ['.ts','.js','.mjs']
});

And modified my serverless.yaml like this:

custom:
  esbuild:
    config: './esbuild.config.js'

@Willis0826
Copy link

Willis0826 commented Apr 7, 2024

Thanks, @ElChapitan and @r-token. Setting the resolveExtensions did solve the problem.
I'm using Serverless TypeScript with the following setup.

import type { AWS } from '@serverless/typescript';
const serverlessConfiguration: AWS = {
  custom: {
    esbuild: {
      bundle: true,
      minify: true,
      sourcemap: false,
      exclude: ['aws-sdk'],
      resolveExtensions: ['.ts', '.js', '.mjs'],
      target: 'node20',
      platform: 'node',
      concurrency: 10,
    }
  }
}

@ElChapitan
Copy link

As a follow up for those coming after, that worked for me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants