Can't get the hello-world-js example to work

Hi, i checked out the GitHub - temporalio/samples-typescript repo to try out temporal in javascript.

I am trying to run the hello-world-js example - samples-typescript/hello-world-js at main · temporalio/samples-typescript · GitHub

The workflow starts fine - src/client.js file

The worker fails to start - node src/worker.js

I am getting the following error (pasting the first few stacktraces, it goes on like this for a bit)

 hello-world-js % node src/worker.js
2022-06-23T14:24:23.421Z [INFO] asset main.js 218 KiB [emitted] (name: main) 1 related asset
2022-06-23T14:24:23.422Z [INFO] runtime modules 1.77 KiB 4 modules
2022-06-23T14:24:23.422Z [INFO] modules by path ./node_modules/@temporalio/ 151 KiB
2022-06-23T14:24:23.422Z [INFO]   modules with warnings 90.9 KiB [warnings] 11 modules
2022-06-23T14:24:23.422Z [INFO]   modules by path ./node_modules/@temporalio/common/lib/ 46.9 KiB
2022-06-23T14:24:23.422Z [INFO]     modules by path ./node_modules/@temporalio/common/lib/converter/*.js 27 KiB 8 modules
2022-06-23T14:24:23.422Z [INFO]     modules by path ./node_modules/@temporalio/common/lib/*.js 19.9 KiB 2 modules
2022-06-23T14:24:23.422Z [INFO]   modules by path ./node_modules/@temporalio/internal-workflow-common/lib/*.js 13.5 KiB
2022-06-23T14:24:23.422Z [INFO]     ./node_modules/@temporalio/internal-workflow-common/lib/index.js 1.3 KiB [built] [code generated]
2022-06-23T14:24:23.423Z [INFO]     + 9 modules
2022-06-23T14:24:23.423Z [INFO] modules by path ./src/*.js 698 bytes
2022-06-23T14:24:23.423Z [INFO]   ./src/workflows-entrypoint-a6fc37e5-d452-4a7d-8147-bc3e060b8689.js 449 bytes [built] [code generated]
2022-06-23T14:24:23.423Z [INFO]   ./src/workflows.js 249 bytes [built] [code generated]
2022-06-23T14:24:23.423Z [INFO] __temporal_custom_payload_converter (ignored) 15 bytes [built] [code generated]
2022-06-23T14:24:23.423Z [INFO] ./node_modules/long/src/long.js 39.2 KiB [built] [code generated]
2022-06-23T14:24:23.423Z [INFO] ./node_modules/ms/index.js 2.95 KiB [built] [code generated]
2022-06-23T14:24:23.423Z [INFO] 
2022-06-23T14:24:23.423Z [INFO] WARNING in ./node_modules/@temporalio/workflow/lib/alea.js
2022-06-23T14:24:23.423Z [INFO] Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
2022-06-23T14:24:23.423Z [INFO] Failed to parse source map from '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/alea.ts' file: Error: ENOENT: no such file or directory, open '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/alea.ts'
2022-06-23T14:24:23.423Z [INFO] Error: Failed to parse source map from '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/alea.ts' file: Error: ENOENT: no such file or directory, open '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/alea.ts'
2022-06-23T14:24:23.423Z [INFO]     at fetchFromFilesystem ([redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/utils.js:129:11)
2022-06-23T14:24:23.423Z [INFO]     at runNextTicks (node:internal/process/task_queues:61:5)
2022-06-23T14:24:23.423Z [INFO]     at processImmediate (node:internal/timers:437:9)
2022-06-23T14:24:23.423Z [INFO]     at async fetchFromURL ([redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/utils.js:239:9)
2022-06-23T14:24:23.423Z [INFO]     at async [redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/index.js:105:11
2022-06-23T14:24:23.423Z [INFO]     at async Promise.all (index 0)
2022-06-23T14:24:23.424Z [INFO]     at async Object.loader ([redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/index.js:89:27)
2022-06-23T14:24:23.424Z [INFO]  @ ./node_modules/@temporalio/workflow/lib/worker-interface.js 34:15-32
2022-06-23T14:24:23.424Z [INFO]  @ ./src/workflows-entrypoint-a6fc37e5-d452-4a7d-8147-bc3e060b8689.js 1:0-68 4:0-19 5:0-18 16:0-15
2022-06-23T14:24:23.424Z [INFO] 
2022-06-23T14:24:23.424Z [INFO] WARNING in ./node_modules/@temporalio/workflow/lib/cancellation-scope.js
2022-06-23T14:24:23.424Z [INFO] Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
2022-06-23T14:24:23.424Z [INFO] Failed to parse source map from '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/cancellation-scope.ts' file: Error: ENOENT: no such file or directory, open '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/cancellation-scope.ts'
2022-06-23T14:24:23.424Z [INFO] Error: Failed to parse source map from '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/cancellation-scope.ts' file: Error: ENOENT: no such file or directory, open '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/cancellation-scope.ts'
2022-06-23T14:24:23.424Z [INFO]     at fetchFromFilesystem ([redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/utils.js:129:11)
2022-06-23T14:24:23.424Z [INFO]     at async fetchFromURL ([redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/utils.js:239:9)
2022-06-23T14:24:23.424Z [INFO]     at async [redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/index.js:105:11
2022-06-23T14:24:23.424Z [INFO]     at async Promise.all (index 0)
2022-06-23T14:24:23.424Z [INFO]     at async Object.loader ([redacted]/temporal-samples-typescript/hello-world-js/node_modules/source-map-loader/dist/index.js:89:27)
2022-06-23T14:24:23.424Z [INFO]  @ ./node_modules/@temporalio/workflow/lib/worker-interface.js 35:29-60
2022-06-23T14:24:23.424Z [INFO]  @ ./src/workflows-entrypoint-a6fc37e5-d452-4a7d-8147-bc3e060b8689.js 1:0-68 4:0-19 5:0-18 16:0-15
2022-06-23T14:24:23.425Z [INFO] 
2022-06-23T14:24:23.425Z [INFO] WARNING in ./node_modules/@temporalio/workflow/lib/errors.js
2022-06-23T14:24:23.425Z [INFO] Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
2022-06-23T14:24:23.425Z [INFO] Failed to parse source map from '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/errors.ts' file: Error: ENOENT: no such file or directory, open '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/errors.ts'
2022-06-23T14:24:23.425Z [INFO] Error: Failed to parse source map from '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/errors.ts' file: Error: ENOENT: no such file or directory, open '[redacted]/temporal-samples-typescript/hello-world-js/node_modules/@temporalio/workflow/src/errors.ts'

Please help.

Hi, sorry about that! It will be fixed in the next release. In the meantime, they’re safe to ignore—your Worker should run fine after all those Failed to parse source map errors.

My bad. I didn’t realize that was not a blocking error! the actual error was down there, it just missed my eyes.

I was getting it because I was trying to connect to a remote temporal server and I was using the wrong connection class.

If it helps anyone, here’s the updated example to connect to a remote instance in javascript.

import {NativeConnection, Worker} from '@temporalio/worker';
import { URL } from 'url';
import * as activities from './activities.js';

async function run() {
  // Step 1: Register Workflows and Activities with the Worker and connect to
  // the Temporal server.
  const connection = await NativeConnection.connect({
    // // Connect to localhost with default ConnectionOptions.
    // // In production, pass options to the Connection constructor to configure TLS and other settings:
    address: '<host>:<port>', // of remote temporal server
    // tls: {} // as provisioned
  });

  const worker = await Worker.create({
    activities,
    workflowsPath: new URL('./workflows.js', import.meta.url).pathname,
    connection,
    taskQueue: 'hello-javascript',
    namespace: '<your_namespace>'
  });
  // Worker connects to localhost by default and uses console.error for logging.
  // Customize the Worker by passing more options to create():
  // https://typescript.temporal.io/api/classes/worker.Worker
  // If you need to configure server connection parameters, see docs:
  // https://docs.temporal.io/typescript/security#encryption-in-transit-with-mtls

  // Step 2: Start accepting tasks on the `hello-javascript` queue
  await worker.run();

  // You may create multiple Workers in a single process in order to poll on multiple task queues.
}

run().catch((err) => {
  console.error(err);
  process.exit(1);
});