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

Sandbox function build failing, can't find dependencies for Lambda function, example: Could not resolve "lodash.get" #2187

Open chrisl777 opened 2 weeks ago

chrisl777 commented 2 weeks ago

Environment information

System:
  OS: macOS 14.5
  CPU: (14) arm64 Apple M3 Max
  Memory: 82.45 MB / 36.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.18.0 - ~/.asdf/installs/nodejs/18.18.0/bin/node
  Yarn: 1.22.22 - ~/.asdf/installs/nodejs/18.18.0/bin/yarn
  npm: 9.8.1 - ~/.asdf/plugins/nodejs/shims/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.4.0
  @aws-amplify/backend: 1.6.0
  @aws-amplify/backend-auth: 1.3.0
  @aws-amplify/backend-cli: 1.4.0
  @aws-amplify/backend-data: 1.1.6
  @aws-amplify/backend-deployer: 1.1.6
  @aws-amplify/backend-function: 1.7.3
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.3
  @aws-amplify/backend-secret: 1.1.4
  @aws-amplify/backend-storage: 1.2.2
  @aws-amplify/cli-core: 1.2.0
  @aws-amplify/client-config: 1.5.1
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.1
  @aws-amplify/sandbox: 1.2.4
  @aws-amplify/schema-generator: 1.2.5
  aws-amplify: 6.8.0
  aws-cdk: 2.165.0
  aws-cdk-lib: 2.165.0
  typescript: 5.6.3
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

tsc --showConfig --project amplify

[DEBUG] 2024-11-01T20:06:04.541Z: amplify/tsconfig.json(3,15): error TS6046: Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext'.

[DEBUG] 2024-11-01T20:06:04.541Z: amplify/tsconfig.json(4,15): error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'.
amplify/tsconfig.json(5,25): error TS6046: Argument for '--moduleResolution' option must be: 'node', 'classic'.

[DEBUG] 2024-11-01T20:06:04.548Z: 
[DEBUG] 2024-11-01T20:06:04.548Z: error Command failed with exit code 1.

info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Unable to build the Amplify backend definition.
Caused By: ✘ [ERROR] Could not resolve "lodash.get"

    packages/backend/amplify/functions/VenuesLambda/handler.ts:4:16:
      4 │ import get from "lodash.get";
        ╵                 ~~~~~~~~~~~~

  You can mark the path "lodash.get" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "aws-amplify"

    packages/backend/amplify/functions/VenuesLambda/handler.ts:7:24:
      7 │ import { Amplify } from "aws-amplify";
        ╵                         ~~~~~~~~~~~~~

  You can mark the path "aws-amplify" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "aws-amplify/data"

    packages/backend/amplify/functions/VenuesLambda/handler.ts:8:31:
      8 │ import { generateClient } from "aws-amplify/data";
        ╵                                ~~~~~~~~~~~~~~~~~~

  You can mark the path "aws-amplify/data" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "lodash.get"

    packages/backend/amplify/functions/VenuesLambda/FoursquareAPI.ts:1:16:
      1 │ import get from "lodash.get"
        ╵                 ~~~~~~~~~~~~

  You can mark the path "lodash.get" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "lodash.get"

    packages/backend/amplify/functions/VenuesLambda/VenueInteractor.ts:1:16:
      1 │ import get from "lodash.get"
        ╵                 ~~~~~~~~~~~~

  You can mark the path "lodash.get" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "uuid"

    packages/backend/amplify/functions/VenuesLambda/VenueInteractor.ts:6:29:
      6 │ import { v4 as uuidv4 } from 'uuid';
        ╵                              ~~~~~~

  You can mark the path "uuid" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

6 of 7 errors shown (disable the message limit with --log-limit=0)
node:child_process:929
    throw err;

Reproduction steps

Created a monorepo with Turborepo.

The apps/mobile-app folder contains an Expo mobile app.

The packages/backend folder contains the Amplify backend.

After trying to run npx ampx sandbox, I see the error output above.

chrisl777 commented 2 weeks ago

I may have "solved" this issue. I ended up:

Then my sandbox command appears to be working.

ykethan commented 1 week ago

Hey @chrisl777, glad to hear updating the NodeJS and re-installing the dependencies fixed the issue. But wanted to get a quick confirmation on the dependencies the error was occurring on. Were the dependencies installed in the root package.json or the under the amplify folder?