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

bug(aws-lambda-nodejs): esbuild preCompilation not finding local tsc #19242

Closed
derdeka opened this issue Mar 4, 2022 · 1 comment · Fixed by #19266
Closed

bug(aws-lambda-nodejs): esbuild preCompilation not finding local tsc #19242

derdeka opened this issue Mar 4, 2022 · 1 comment · Fixed by #19266
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@derdeka
Copy link

derdeka commented Mar 4, 2022

What is the problem?

The esbuild preCompilation option requires typescript to be installed globally and does not find a local (project) installation.

Reproduction Steps

With no global typescript installation, but local typescript dev dependency and the following configuration:

new NodejsFunction(scope, id, {
  ...
  bundling: {
    preCompilation: true
  }
})

What did you expect to happen?

tsc command should be found when typescript is locally installed.

What actually happened?

The command "undefined" is either misspelled or could not be found.

CDK CLI Version

2.15.0

Framework Version

2.15.0

Node.js Version

14.15.3

OS

Windows 10

Language

Typescript

Language Version

TypeScript (4.3.5)

Other information

Searching for command tsc is happening here:

Bundling.tscInstallation = Bundling.tscInstallation ?? PackageInstallation.detect('tsc');

// Check local version first
const version = tryGetModuleVersionFromRequire(module);
if (version) {
return {
isLocal: true,
version,
};
}

It tries to find the local installation using require('tsc/package.json') which can not be found. The package name has to be typescript instead of tsc to detect it correctly.

export function tryGetModuleVersionFromRequire(mod: string): string | undefined {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require(`${mod}/package.json`).version;
} catch (err) {
return undefined;
}
}

@derdeka derdeka added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 4, 2022
@NGL321 NGL321 added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Mar 7, 2022
jogold added a commit to jogold/aws-cdk that referenced this issue Mar 7, 2022
The package name is `typescript`, the bin is `tsc`.

Closes aws#19242
@mergify mergify bot closed this as completed in #19266 Mar 7, 2022
mergify bot pushed a commit that referenced this issue Mar 7, 2022
The package name is `typescript`, the bin is `tsc`.

Closes #19242


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Mar 7, 2022

⚠️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.

TheRealAmazonKendra pushed a commit to TheRealAmazonKendra/aws-cdk that referenced this issue Mar 11, 2022
The package name is `typescript`, the bin is `tsc`.

Closes aws#19242


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants