-
Notifications
You must be signed in to change notification settings - Fork 153
Bug: unable to build with tsc
when not using @middy/core
#1068
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
Comments
Hi @rreddypally thank you for opening this issue. I have tried reproducing the issue you describe but unfortunately I am not able to. In the docs we recommend to import the Tracer directly (i.e. I have made a screen record in which I create a new project from zero and I set up the latest version of Tracer in a function, then bundle it, and then deploy & run it. As mentioned, I have tested both As you'll see in the video, I never install Middy and I only install 2022-08-22.14-03-14.mp4Additionally, as a side note, you'll see that the file containing the Please let me know if this answers your question. |
EDIT from maintainer: removed zip archive Hi @dreamorosi, thanks for taking time and record the extensive demo. I have attached a typescript demo which fails to compile without middy. Steps:
I think Hope this helps. |
Unfortunately I'm not allowed to download archives from public websites on my machine. Could you please provide a sample repo here on GitHub with its content so I can take a look? Thanks for your understanding |
No problem at all. Here is the repo: https://github.com/rreddypally/tracer-demo Let me know if you have trouble accessing it. |
Thank you for providing the repo. I can confirm that I am able to reproduce the issue you describe, which happens only when bundling with I was also able to confirm that the issue affects the Logger & Metrics utilities as well. We're going to need a bit more time to investigate this though, the fix that you suggested in the PR #1069 does not seem to fix the issue for me, at least when using the standard I'm going to rename the issue, after that would you be so kind to please open two more issues one for Metrics & another for Logger with the same title? Would really appreciate and also would like to reflect that you actually discovered the issue. |
tsc
when not using @middy/core
@rreddypally: In the meanwhile, if you don't want to use I know it's not ideal but it's a temporary solution while we find a better one. |
@dreamorosi thanks for taking time to recreate the issue. I can work with the dev dependency in the meantime as we use esbuild to bundle the code for deployment. I have created issues for Logger and Metrics as requested. |
Thank you @rreddypally, just to be clear, if you're using Thank you also for opening the issues, we'll discuss them with the team and report here any development |
We use |
Thanks again @rreddypally for reporting this bug and providing a repo to reproduce the issue. Upon a bit of investigation playing around with the repo
Notice the 4th line, which is causing an error. Steps to reproduce:
The fix for this issue is make sure that the middy middleware file is not imported elsewhere like other folders and files, by removing it from example from the index file imports. |
tsc
when not using @middy/core
tsc
when not using @middy/core
Hi "AWS Lambda Powertools Team", |
Hi @ValeryShvyndzikau, that's great to hear you'll be adopting the utilities. I just want to acknowledge that I read your message, I will be talking about this issue with @dreamorosi this week and we'll get back to you with a more concrete answer by the end of the week. |
To build on Sara's previous comment, currently the packages are exported like so:
File export * from './helpers';
export * from './Tracer';
export * from './TracerInterface';
export * from './middleware/middy'; which once built and packaged allows consumers to import like: import { Tracer, captureLambdaHandler } from "@aws-lambda-powertools/tracer"; or, if not using the Middy middleware: import { Tracer } from "@aws-lambda-powertools/tracer"; As reported by the discussion in this thread, when bundling with In order to fix this, it seems that we need to change the main entry point like so: export * from './helpers';
export * from './Tracer';
export * from './TracerInterface';
-- export * from './middleware/middy'; This would allow everyone to still import the main import { Tracer } from "@aws-lambda-powertools/tracer"; but, most notably, it'll require those who use the middleware to change their imports to: import { captureLambdaHandler } from "@aws-lambda-powertools/tracer/middleware"; Now, this would solve the issue in question, but it would also constitute a breaking change, which will require us to do a major release to |
Yes I thought of the same solution as well. But I see some problem when you have installed the package and you do the proposed import import { captureLambdaHandler } from "@aws-lambda-powertools/tracer/middleware"; The build will still fail as |
I have tested the solution I described above (i.e. removing the export from 2023-01-11.12-13-23.mp4As the video shows, when importing only It seems that by modifying the imports like suggested, when importing only from I'd like to avoid creating other dedicated packages only for the middleware utilities unless there's no other way that we can make this work without. Mainly for the reason that maintaining and distributing these packages will result in a significant overhead. |
Thanks to @saragerion, we have a workaround that we feel comfortable releasing in the short term, that doesn't require breaking changes in the imports, and that fixes the issue described above. You can find more details in the linked PR #1225. If all goes well during review we should be able to make it available in the next release. Thanks to everyone who contributed to the discussion. |
|
We just released version You can read more about the fix in #1225, however now you should be able to transpile your functions with I have tested "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! |
Bug description
EDIT: see this comment for updated info after triage.
The import statement in Tracer.ts for
TracerInterface
is importing all the modules from the root. https://github.com/awslabs/aws-lambda-powertools-typescript/blob/main/packages/tracer/src/Tracer.ts#L3.I am trying to use tracer module without the need to install middy.
Expected Behavior
Should be able to use Tracer without the need to import middy when its not used.
Current Behavior
This behavior is forcing to import middy middleware
Possible Solution
import { TracerInterface } from './TracerInterface';
Steps to Reproduce
npm i @aws-lambda-powertools/tracer
import { Tracer } from "@aws-lambda-powertools/tracer/lib/Tracer";
error TS2307: Cannot find module '@middy/core' or its corresponding type declarations
.Environment
The text was updated successfully, but these errors were encountered: