Skip to content

Bug: unable to build with tsc when not using @middy/core #1081

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

Closed
rreddypally opened this issue Aug 28, 2022 · 2 comments · Fixed by #1225
Closed

Bug: unable to build with tsc when not using @middy/core #1081

rreddypally opened this issue Aug 28, 2022 · 2 comments · Fixed by #1225
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped metrics This item relates to the Metrics Utility

Comments

@rreddypally
Copy link

Bug description

The code doesn't compile using tsc when using the Metrics module without middy.

Expected Behavior

Should be able to use Metrics without the need to import middy when its not used. Unlike Logger importing the submodule via import { Metrics } from '@aws-lambda-powertools/metrics/lib/Metrics'; fails to compile too.

Current Behavior

Middy is required atleast as the dev dependency while compiling with tsc. This is not a problem when esbuild or ts-node is used.

Possible Solution

Steps to Reproduce

Steps:

  1. npm install and import Metrics using import { Metrics } from "@aws-lambda-powertools/metrics";
  2. Build project using tsc
  3. Expect this error Cannot find module '@middy/core' or its corresponding type declarations.

package.json

{
  "scripts": {
    "build": "npm i && tsc metrics-demo.ts"
  },
  "dependencies": {
    "@aws-lambda-powertools/metrics": "1.2.0",
    "@types/aws-lambda": "8.10.101"
    
  },
  "devDependencies": {
    "typescript": "4.7.4"
  }
}

metrics-demo

import { Metrics } from '@aws-lambda-powertools/metrics/lib/Metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

tsconfig.json

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "target": "ES2021",
        "module": "CommonJS"
    }
}

Environment

  • Powertools version used: 1.2.1
  • Packaging format (Layers, npm): npm
  • AWS Lambda function runtime: node16
  • Debugging logs: n/a

Related issues, RFCs

#1068
#1080

@rreddypally rreddypally added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Aug 28, 2022
@saragerion saragerion added the help-wanted We would really appreciate some support from community for this one label Sep 8, 2022
@dreamorosi dreamorosi added the good-first-issue Something that is suitable for those who want to start contributing label Oct 27, 2022
@dreamorosi dreamorosi removed the triage This item has not been triaged by a maintainer, please wait label Nov 13, 2022
@dreamorosi dreamorosi added metrics This item relates to the Metrics Utility blocked This item's progress is blocked by external dependency or reason need-more-information Requires more information before making any calls labels Nov 13, 2022
@dreamorosi dreamorosi changed the title Bug (Metrics): unable to build with tsc when not using @middy/core Bug: unable to build with tsc when not using @middy/core Nov 14, 2022
@dreamorosi dreamorosi moved this from Backlog to Pending review in AWS Lambda Powertools for TypeScript Jan 11, 2023
@dreamorosi dreamorosi added confirmed The scope is clear, ready for implementation and removed good-first-issue Something that is suitable for those who want to start contributing help-wanted We would really appreciate some support from community for this one blocked This item's progress is blocked by external dependency or reason need-more-information Requires more information before making any calls labels Jan 11, 2023
@dreamorosi dreamorosi self-assigned this Jan 11, 2023
@dreamorosi dreamorosi linked a pull request Jan 11, 2023 that will close this issue
13 tasks
@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in AWS Lambda Powertools for TypeScript Jan 13, 2023
@github-actions
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@dreamorosi
Copy link
Contributor

We just released version 1.5.1 that should fix the issue.

You can read more about the fix in #1225, however now you should be able to transpile your functions with tsc without having @middy/core in your codebase.

I have tested v1.5.1. in the repository provided here, and the code now compiles successfully to this:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tracer_1 = require("@aws-lambda-powertools/tracer");
// import { captureLambdaHandler } from '@aws-lambda-powertools/tracer'
const tracer = new tracer_1.Tracer();

Hope this helps!

@dreamorosi dreamorosi moved this from Coming soon to Shipped in AWS Lambda Powertools for TypeScript Jan 13, 2023
@dreamorosi dreamorosi added completed This item is complete and has been merged/shipped and removed confirmed The scope is clear, ready for implementation labels Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped metrics This item relates to the Metrics Utility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants