Skip to content

Commit a23f656

Browse files
rtpascualKamil Sobol
andauthored
add more forms of transform errors to cdk error mapping (#2263)
* add more forms of transform errors to cdk error mapping * Update packages/backend-deployer/src/cdk_error_mapper.ts Co-authored-by: Kamil Sobol <[email protected]> --------- Co-authored-by: Kamil Sobol <[email protected]>
1 parent 691e7ca commit a23f656

File tree

3 files changed

+117
-1
lines changed

3 files changed

+117
-1
lines changed

.changeset/great-otters-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/backend-deployer': patch
3+
---
4+
5+
add more forms of transform errors to cdk error mapping

packages/backend-deployer/src/cdk_error_mapper.test.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,106 @@ npm error A complete log of this run can be found in: /home/some-path/.npm/_logs
406406
errorName: 'AccessDeniedError',
407407
expectedDownstreamErrorMessage: undefined,
408408
},
409+
{
410+
errorMessage:
411+
`Error: Transform failed with 1 error:` +
412+
EOL +
413+
`/Users/some-path/amplify/storage/resource.ts:1:2: ERROR: Expected identifier but found }` +
414+
EOL +
415+
`at failureErrorWithLog (/Users/some-path/esbuild/lib/main.js:123:45)` +
416+
EOL +
417+
`at /Users/some-path/esbuild/lib/main.js:678:90`,
418+
expectedTopLevelErrorMessage:
419+
'/Users/some-path/amplify/storage/resource.ts:1:2: ERROR: Expected identifier but found }',
420+
errorName: 'ESBuildError',
421+
expectedDownstreamErrorMessage: undefined,
422+
},
423+
{
424+
errorMessage:
425+
`Error [TransformError]:` +
426+
EOL +
427+
`You installed esbuild for another platform than the one you're currently using.
428+
This won't work because esbuild is written with native code and needs to
429+
install a platform-specific binary executable.` +
430+
EOL +
431+
`Specifically the @esbuild/linux-arm64 package is present but this platform
432+
needs the @esbuild/darwin-arm64 package instead. People often get into this
433+
situation by installing esbuild on Windows or macOS and copying node_modules
434+
into a Docker image that runs Linux, or by copying node_modules between
435+
Windows and WSL environments.` +
436+
EOL +
437+
`If you are installing with npm, you can try not copying the node_modules
438+
directory when you copy the files over, and running npm ci or npm install
439+
on the destination platform after the copy. Or you could consider using yarn
440+
instead of npm which has built-in support for installing a package on multiple
441+
platforms simultaneously.` +
442+
EOL +
443+
`If you are installing with yarn, you can try listing both this platform and the
444+
other platform in your .yarnrc.yml file using the supportedArchitectures
445+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
446+
Keep in mind that this means multiple copies of esbuild will be present.` +
447+
EOL +
448+
// eslint-disable-next-line spellcheck/spell-checker
449+
`Another alternative is to use the esbuild-wasm package instead, which works
450+
the same way on all platforms. But it comes with a heavy performance cost and
451+
can sometimes be 10x slower than the esbuild package, so you may also not want to do that.`,
452+
expectedTopLevelErrorMessage:
453+
`You installed esbuild for another platform than the one you're currently using.
454+
This won't work because esbuild is written with native code and needs to
455+
install a platform-specific binary executable.` +
456+
EOL +
457+
`Specifically the @esbuild/linux-arm64 package is present but this platform
458+
needs the @esbuild/darwin-arm64 package instead. People often get into this
459+
situation by installing esbuild on Windows or macOS and copying node_modules
460+
into a Docker image that runs Linux, or by copying node_modules between
461+
Windows and WSL environments.` +
462+
EOL +
463+
`If you are installing with npm, you can try not copying the node_modules
464+
directory when you copy the files over, and running npm ci or npm install
465+
on the destination platform after the copy. Or you could consider using yarn
466+
instead of npm which has built-in support for installing a package on multiple
467+
platforms simultaneously.` +
468+
EOL +
469+
`If you are installing with yarn, you can try listing both this platform and the
470+
other platform in your .yarnrc.yml file using the supportedArchitectures
471+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
472+
Keep in mind that this means multiple copies of esbuild will be present.` +
473+
EOL +
474+
// eslint-disable-next-line spellcheck/spell-checker
475+
`Another alternative is to use the esbuild-wasm package instead, which works
476+
the same way on all platforms. But it comes with a heavy performance cost and
477+
can sometimes be 10x slower than the esbuild package, so you may also not want to do that.`,
478+
errorName: 'ESBuildError',
479+
expectedDownstreamErrorMessage: undefined,
480+
},
481+
{
482+
errorMessage:
483+
`Error [TransformError]: The package esbuild-package could not be found, and is needed by esbuild.` +
484+
EOL +
485+
`If you are installing esbuild with npm, make sure that you don't specify the
486+
--no-optional or --omit=optional flags. The optionalDependencies feature
487+
of package.json is used by esbuild to install the correct binary executable
488+
for your current platform.
489+
` +
490+
EOL +
491+
`at generateBinPath (/Users/some-path/esbuild/lib/main.js:123:45)` +
492+
EOL +
493+
`at /Users/some-path/esbuild/lib/main.js:678:90`,
494+
expectedTopLevelErrorMessage:
495+
`The package esbuild-package could not be found, and is needed by esbuild.` +
496+
EOL +
497+
`If you are installing esbuild with npm, make sure that you don't specify the
498+
--no-optional or --omit=optional flags. The optionalDependencies feature
499+
of package.json is used by esbuild to install the correct binary executable
500+
for your current platform.
501+
` +
502+
EOL +
503+
`at generateBinPath (/Users/some-path/esbuild/lib/main.js:123:45)` +
504+
EOL +
505+
`at /Users/some-path/esbuild/lib/main.js:678:90`,
506+
errorName: 'ESBuildError',
507+
expectedDownstreamErrorMessage: undefined,
508+
},
409509
];
410510

411511
void describe('invokeCDKCommand', { concurrency: 1 }, () => {

packages/backend-deployer/src/cdk_error_mapper.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,25 @@ export class CdkErrorMapper {
248248
{
249249
// If there are multiple errors, capture all lines containing the errors
250250
errorRegex: new RegExp(
251-
`\\[TransformError\\]: Transform failed with .* error(s?):${this.multiLineEolRegex}(?<esBuildErrorMessage>(.*ERROR:.*${this.multiLineEolRegex})+)`
251+
`(\\[TransformError\\]|Error): Transform failed with .* error(s?):${this.multiLineEolRegex}(?<esBuildErrorMessage>(.*ERROR:.*${this.multiLineEolRegex})+)`
252252
),
253253
humanReadableErrorMessage: '{esBuildErrorMessage}',
254254
resolutionMessage:
255255
'Fix the above mentioned type or syntax error in your backend definition.',
256256
errorName: 'ESBuildError',
257257
classification: 'ERROR',
258258
},
259+
{
260+
// Captures other forms of transform error
261+
errorRegex: new RegExp(
262+
`Error \\[TransformError\\]:(${this.multiLineEolRegex}|\\s)?(?<esBuildErrorMessage>(.*(${this.multiLineEolRegex})?)+)`
263+
),
264+
humanReadableErrorMessage: '{esBuildErrorMessage}',
265+
resolutionMessage:
266+
'Make sure esbuild is installed and is compatible with the platform you are currently using.',
267+
errorName: 'ESBuildError',
268+
classification: 'ERROR',
269+
},
259270
{
260271
errorRegex: /Amplify Backend not found in/,
261272
humanReadableErrorMessage:

0 commit comments

Comments
 (0)