-
Notifications
You must be signed in to change notification settings - Fork 4.4k
bug(aws-lambda-nodejs): esbuild preCompilation not finding local tsc #19242
Copy link
Copy link
Closed
Labels
@aws-cdk/aws-lambda-nodejsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1
Description
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.
aws-cdk/packages/@aws-cdk/aws-lambda-nodejs/lib/util.ts
Lines 91 to 98 in de31f9f
| 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; | |
| } | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-lambda-nodejsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1