Error building workflows when executing test with jest

I’m trying to use the hello world typescript sample as a POC for integrating temporal into an nx monorepo. The code is building and executing just fine for the most part, but I’m having trouble getting the workflows tests working.

The tests are copied almost verbatim from here, but the imports and workflowsPath have been updated to reflect a slightly different layout.

I have checked the docs, and I am using a compatible version of jest (29) and I am using ts-jest. The primary error seems to be SyntaxError: Unexpected token 'export' but I can’t figure out why temporal is having trouble building my typescript code (which does, in fact, use export).

2023-12-04T19:47:29.542Z [ERROR] asset workflow-bundle-5655ff634c496f439b3e.js 752 KiB [emitted] [immutable] (name: main)
2023-12-04T19:47:29.542Z [ERROR] modules by path ./node_modules/@temporalio/ 186 KiB
2023-12-04T19:47:29.542Z [ERROR]   modules by path ./node_modules/@temporalio/common/ 81.3 KiB 22 modules
2023-12-04T19:47:29.542Z [ERROR]   modules by path ./node_modules/@temporalio/workflow/ 102 KiB
2023-12-04T19:47:29.542Z [ERROR]     ./node_modules/@temporalio/workflow/lib/worker-interface.js 11.3 KiB [built] [code generated]
2023-12-04T19:47:29.542Z [ERROR]     ./node_modules/@temporalio/workflow/lib/cancellation-scope.js 7 KiB [built] [code generated]
2023-12-04T19:47:29.543Z [ERROR]     + 12 modules
2023-12-04T19:47:29.543Z [ERROR]   ./node_modules/@temporalio/worker/lib/workflow-log-interceptor.js 2.42 KiB [built] [code generated]
2023-12-04T19:47:29.543Z [ERROR] modules by path ./libs/workflows/hello-world/src/ 583 bytes
2023-12-04T19:47:29.543Z [ERROR]   ./libs/workflows/hello-world/src/index-autogenerated-entrypoint.cjs 544 bytes [built] [code generated]
2023-12-04T19:47:29.543Z [ERROR]   ./libs/workflows/hello-world/src/index.ts 39 bytes [not cacheable] [built] [code generated] [1 error]
2023-12-04T19:47:29.543Z [ERROR] __temporal_custom_payload_converter (ignored) 15 bytes [built] [code generated]
2023-12-04T19:47:29.543Z [ERROR] __temporal_custom_failure_converter (ignored) 15 bytes [built] [code generated]
2023-12-04T19:47:29.543Z [ERROR] ./node_modules/long/umd/index.js 43.1 KiB [built] [code generated]
2023-12-04T19:47:29.543Z [ERROR]
2023-12-04T19:47:29.543Z [ERROR] ERROR in ./libs/workflows/hello-world/src/index.ts
2023-12-04T19:47:29.544Z [ERROR] Module build failed (from ./node_modules/swc-loader/src/index.js):
2023-12-04T19:47:29.544Z [ERROR] NonErrorEmittedError: (Emitted value instead of an instance of Error) SyntaxError: Unexpected token 'export'

Has anybody seen this error or does anyone know what the cause might be?

This appears to be caused by the order of elements in the jest configuration option for moduleFileExtensions. The nx jest preset configures this to list ts first. Moving ts to be after js and mjs solves the problem.

I added this to the jest.config.ts in my nx “javascript” library to get the workflow bundling working.

    moduleFileExtensions: ['js', 'mjs', 'ts', 'html'],
2 Likes

Huge thanks for coming back to post this. No idea how you found this.