aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
184 stars 62 forks source link

SyntaxError: The requested module '@aws-amplify/platform-core' does not provide an export named 'CallerDirectoryExtractor' #2039

Closed jitinrathi910949 closed 1 month ago

jitinrathi910949 commented 1 month ago

I created a lambda function using gen2 as follow:

amplify/functions/send-link-file/resource.ts file:

`import { defineFunction } from '@aws-amplify/backend';

export const sendReportEmail = defineFunction({
  name: 'send-report-email',
  entry: './handler.ts',
  timeoutSeconds: 180
});`

hander.ts file:


import {SendRawEmailCommand, SESClient, } from '@aws-sdk/client-ses';
import { CreateForm1 } from './pdf';

const sesClient = new SESClient({region: 'ap-south-1'});

export const handler = async (event: any, context: any) => {
// rest of the logic...

return 'success';

}

backend.ts file:

import { defineBackend } from '@aws-amplify/backend';
import {Effect, PolicyStatement} from "aws-cdk-lib/aws-iam"
import { auth } from './auth/resource.js';
import { data } from './data/resource.js';
import { sendLinkEmail } from './functions/send-link-email/resource';
import { sendReportEmail } from './functions/send-report-email/resource';

const backend = defineBackend({
  auth,
  data,
  sendLinkEmail,
  sendReportEmail
});

Everything works well in sandbox. But while deployment, I am getting following error:


2024-09-22T19:41:30.538Z [INFO]: # Executing command: npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID --debug

54 2024-09-22T19:41:55.774Z [INFO]: [DEBUG] 2024-09-22T19:41:55.773Z: npm

55 2024-09-22T19:41:55.780Z [INFO]: [DEBUG] 2024-09-22T19:41:55.774Z: WARN exec The following package was not found and will be installed: cdk@2.159.1

56 2024-09-22T19:42:00.121Z [INFO]: [DEBUG] 2024-09-22T19:42:00.120Z: /codebuild/output/src4216656133/src/medical-amplify/node_modules/@aws-amplify/backend-function/src/factory.ts:35

57 CallerDirectoryExtractor,
    ^

59 SyntaxError: The requested module '@aws-amplify/platform-core' does not provide an export named 'CallerDirectoryExtractor'

60 at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)

61 at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Expected behavior As it works well in the sandbox. This should deploy correctly.

Screenshots

Screenshot 2024-09-23 at 1 30 29 AM Screenshot 2024-09-23 at 1 30 41 AM

Desktop (please complete the following information):

ykethan commented 1 month ago

Hey @jitinrathi910949, thank you for reaching out. Could you run npx ampx info and provide us the output? Additionally, could you verify if the aws-cdk and aws-cdk-lib are currently installed in the project?

jitinrathi910949 commented 1 month ago

Hey @jitinrathi910949, thank you for reaching out. Could you run npx ampx info and provide us the output? Additionally, could you verify if the aws-cdk and aws-cdk-lib are currently installed in the project?

Hi @ykethan , Yes I have both the packages installed.

Here is the output for npx ampx info

System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M1
  Memory: 140.33 MB / 8.00 GB
  Shell: /bin/bash
Binaries:
  Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
  Yarn: 3.6.4 - ~/.yarn/bin/yarn
  npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.0
  @aws-amplify/backend: 1.2.1
  @aws-amplify/backend-auth: 1.1.4
  @aws-amplify/backend-cli: 1.2.6
  @aws-amplify/backend-data: 1.1.3
  @aws-amplify/backend-deployer: 1.1.2
  @aws-amplify/backend-function: 1.4.0
  @aws-amplify/backend-output-schemas: 1.2.0
  @aws-amplify/backend-output-storage: 1.1.1
  @aws-amplify/backend-secret: 1.1.1
  @aws-amplify/backend-storage: 1.1.2
  @aws-amplify/cli-core: 1.1.2
  @aws-amplify/client-config: 1.3.0
  @aws-amplify/deployed-backend-client: 1.4.0
  @aws-amplify/form-generator: 1.0.1
  @aws-amplify/model-generator: 1.0.6
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.2.1
  @aws-amplify/sandbox: 1.2.1
  @aws-amplify/schema-generator: 1.2.2
  aws-amplify: 6.6.0
  aws-cdk: 2.159.1
  aws-cdk-lib: 2.158.0
  typescript: 5.6.2
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables
ykethan commented 1 month ago

Hey @jitinrathi910949, thank you for the information. Could you try removing the local node_modules and package-lock.json and reinstall them with latest versions of Amplify backend packages.

  "@aws-amplify/backend": "^1.3.0",
   "@aws-amplify/backend-cli": "^1.2.8",
ChristopherGabba commented 1 month ago

@ykethan @jitinrathi910949 I was also experiencing this issue after updating my @aws-amplify/backend to 1.2.2 a couple of weeks ago. After following @ykethan's package upgrade and removing node-modules looks like it finally deployed successfully, so that fixed my problem.

ykethan commented 1 month ago

@ChristopherGabba thank you for the confirmation, closing the issue do reach out if you are still experiencing this.