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

amplify:<function-name> scripts that install devdependencies for build are installing production dependencies due to NODE_ENV=production #11785

Closed
2 tasks done
chrisl777 opened this issue Jan 14, 2023 · 5 comments
Labels
bug Something isn't working duplicate If marked with duplicate, issue will be closed & original will be added for traceability functions Issues tied to the functions category pending-release Code has been merged but pending release

Comments

@chrisl777
Copy link

chrisl777 commented Jan 14, 2023

How did you install the Amplify CLI?

yarn

If applicable, what version of Node.js are you using?

14.19.1

Amplify CLI Version

10.6.1

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Describe the bug

Without any changes to our configuration, within the last week, the Amplify console build has recently stopped including the executable code for TypeScript Lambdas into the deployed Lambdas. We have been running under the same Lambda configuration for over a year.

I noticed b/c our CloudWatch logs for the Lambdas were showing an error:

"errorType": "Runtime.HandlerNotFound",
"errorMessage": "index.handler is undefined or not exported"

The result of the Amplify console build that is stored in the deployment bucket in S3 is just the package.json, the compiled index.js is not included in the S3 deployment.

Running the build script locally with yarn amplify:{LambdaName} does output an index.js to the src/ folder within the Lambda.

Note that if we run amplify push manually from the command line, then the Lambdas do get created properly and the resulting executable index.js files are included into the deployment.

Here's the folder structure for each Lambda (within /amplify/backend/function/...):

-dist/ (not committed, resulting build folder)
-lib/
--source files (.ts) 
-src/
--output index.js 
-{LambdaName}-cloudformation-template.json 
-package.json 
-tsconfig.json 
-webpack.config.js
-yarn.lock 

The tsconfig.json files:

{
  "compilerOptions": {
    "lib": [
      "es2017",
      "DOM"
    ], 
    "target": "es2017", 
    "module": "commonjs", 
    "moduleResolution": "node",     
    "baseUrl": "./",
    "sourceMap": true,
    "esModuleInterop": true,
    "types": [
      "node",
      "jest"
    ],
  },
  "exclude": [
    "node_modules",
    "**/*.test.ts"
  ]
} 

The build script in our root package.json:

"amplify:{LambdaName}": "cd amplify/backend/function/{LambdaName} && yarn install && webpack-cli && cd -",

I suspect that we may need to add "outDir": "./src" to our tsconfig.json, since that is where the index.js files end up, but I'm not sure, since it is working with a local amplify push.

Expected behavior

We expect that the compiled index.js files will be included in the deployment buckets (and thus deployed as part of the deployed Lambda files).

Reproduction steps

  1. Create TypeScript Lambdas per the docs: https://docs.amplify.aws/cli/function/build-options/
  2. Set up Amplify console CI/CD process.
  3. Push code to repo
  4. Observe the resulting built Lambdas, the folders do not contain index.js files.

Project Identifier

ac2fa547ce795a99c33b7773e2d59f15

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@chrisl777 chrisl777 added the pending-triage Issue is pending triage label Jan 14, 2023
@josefaidt
Copy link
Contributor

Hey @chrisl777 👋 thanks for raising this! It appears the issue you are experiencing is likely caused by this active bug #11717

In the bug report it is noted that a NODE_ENV flag set to production is causing the CLI to only install dependencies (i.e. not including devDependencies such as typescript), subsequently causing the amplify:<function-name> npm script to silently fail.

@josefaidt josefaidt added functions Issues tied to the functions category pending-response Issue is pending response from the issue author duplicate If marked with duplicate, issue will be closed & original will be added for traceability labels Jan 17, 2023
@chrisl777
Copy link
Author

@josefaidt Any update on this bug?

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Feb 1, 2023
@josefaidt josefaidt added bug Something isn't working pending-release Code has been merged but pending release and removed pending-triage Issue is pending triage labels Feb 1, 2023
@josefaidt
Copy link
Contributor

Hey @chrisl777 this fix is pending release and should be available in the next version of the CLI

@chrisl777
Copy link
Author

@josefaidt Awesome, you guys rock!

@josefaidt josefaidt changed the title TypeScript Lambdas are empty upon deployment amplify:<function-name> scripts that install devdependencies for build are installing production dependencies due to NODE_ENV=production Feb 1, 2023
@josefaidt
Copy link
Contributor

This fix was released with Amplify CLI 10.7.0 🎉

closing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate If marked with duplicate, issue will be closed & original will be added for traceability functions Issues tied to the functions category pending-release Code has been merged but pending release
Projects
None yet
Development

No branches or pull requests

2 participants