temporalio / samples-typescript

Other
317 stars 122 forks source link

[Bug] Webpack error when adding tests on food-delivery example #313

Closed redpanda closed 9 months ago

redpanda commented 11 months ago

What are you really trying to do?

I'm running some experiments with mocha on the current samples, and I've some issues with the food-delivery sample.

Describe the bug

When I run the tests, I have the following error during the worker instantiation:

> workflows@0.0.1 test
> mocha --require ts-node/register --require source-map-support/register mocha/*.test.ts

  order workflow
2023-11-27T11:27:06.057Z [ERROR] asset workflow-bundle-fd27de252388b669ec89.js 752 KiB [emitted] [immutable] (name: main)
2023-11-27T11:27:06.059Z [ERROR] modules by path ../../node_modules/@temporalio/ 186 KiB
2023-11-27T11:27:06.059Z [ERROR]   modules by path ../../node_modules/@temporalio/common/ 81.3 KiB 22 modules
2023-11-27T11:27:06.059Z [ERROR]   modules by path ../../node_modules/@temporalio/workflow/ 102 KiB
2023-11-27T11:27:06.059Z [ERROR]     ../../node_modules/@temporalio/workflow/lib/worker-interface.js 11.3 KiB [built] [code generated]
2023-11-27T11:27:06.059Z [ERROR]     ../../node_modules/@temporalio/workflow/lib/cancellation-scope.js 7 KiB [built] [code generated]
2023-11-27T11:27:06.059Z [ERROR]     + 12 modules
2023-11-27T11:27:06.059Z [ERROR]   ../../node_modules/@temporalio/worker/lib/workflow-log-interceptor.js 2.42 KiB [built] [code generated]
2023-11-27T11:27:06.059Z [ERROR] modules by path ./ 603 bytes
2023-11-27T11:27:06.060Z [ERROR]   ./index-autogenerated-entrypoint.cjs 564 bytes [built] [code generated]
2023-11-27T11:27:06.060Z [ERROR]   ./index.ts 39 bytes [built] [code generated] [1 error]
2023-11-27T11:27:06.060Z [ERROR] __temporal_custom_payload_converter (ignored) 15 bytes [built] [code generated]
2023-11-27T11:27:06.060Z [ERROR] __temporal_custom_failure_converter (ignored) 15 bytes [built] [code generated]
2023-11-27T11:27:06.060Z [ERROR] ../../node_modules/long/umd/index.js 43.1 KiB [built] [code generated]
2023-11-27T11:27:06.060Z [ERROR] 
2023-11-27T11:27:06.060Z [ERROR] ERROR in ./index.ts
2023-11-27T11:27:06.060Z [ERROR] Module build failed (from ../../node_modules/swc-loader/src/index.js):
2023-11-27T11:27:06.060Z [ERROR] Error: Bindings not found.
2023-11-27T11:27:06.060Z [ERROR]     at Compiler.<anonymous> (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/@swc/core/index.js:225:19)
2023-11-27T11:27:06.060Z [ERROR]     at Generator.next (<anonymous>)
2023-11-27T11:27:06.060Z [ERROR]     at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/@swc/core/index.js:34:71
2023-11-27T11:27:06.060Z [ERROR]     at new Promise (<anonymous>)
2023-11-27T11:27:06.060Z [ERROR]     at __awaiter (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/@swc/core/index.js:30:12)
2023-11-27T11:27:06.060Z [ERROR]     at Compiler.transform (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/@swc/core/index.js:202:16)
2023-11-27T11:27:06.060Z [ERROR]     at Object.transform (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/@swc/core/index.js:344:21)
2023-11-27T11:27:06.060Z [ERROR]     at Object.<anonymous> (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/swc-loader/src/index.js:86:21)
2023-11-27T11:27:06.060Z [ERROR]  @ ./index-autogenerated-entrypoint.cjs 9:9-139
2023-11-27T11:27:06.060Z [ERROR] 
2023-11-27T11:27:06.060Z [ERROR] webpack 5.88.1 compiled with 1 error in 676 ms
Error: Webpack finished with errors, if you're unsure what went wrong, visit our troubleshooting page at https://docs.temporal.io/typescript/troubleshooting#webpack-errors
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/@temporalio/worker/src/workflow/bundler.ts:271:17
    at finalCallback (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:441:32)
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:505:17
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/HookWebpackError.js:68:3
    at Hook.eval [as callAsync] (eval at create (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/Hook.js:18:14)
    at Cache.storeBuildDependencies (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Cache.js:122:37)
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:501:19
    at Hook.eval [as callAsync] (eval at create (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/Hook.js:18:14)
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:498:23
    at Compiler.emitRecords (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:919:5)
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:490:11
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:885:14
    at Hook.eval [as callAsync] (eval at create (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/Hook.js:18:14)
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:882:27
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/neo-async/async.js:2818:7
    at done (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/neo-async/async.js:3522:9)
    at Hook.eval [as callAsync] (eval at create (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/tapable/lib/Hook.js:18:14)
    at /Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/webpack/lib/Compiler.js:736:33
    at Immediate.<anonymous> (/Users/jleger/Projects/temporal/samples-typescript/food-delivery/node_modules/memfs/lib/volume.js:637:13)
    at processImmediate (node:internal/timers:466:21)
    at process.topLevelDomainCallback (node:domain:161:15)
    at process.callbackTrampoline (node:internal/async_hooks:128:24)
npm ERR! Lifecycle script `test` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: workflows@0.0.1 
npm ERR!   at location: /Users/jleger/Projects/temporal/samples-typescript/food-delivery/packages/workflows 

Minimal Reproduction

I created a branch on my fork; the code is here and the diff here.

To run the tests you have to run the following commands:

cd food-delivery/packages/workflows
nvm use
npm run test

Environment/Versions

Additional context

mjameswh commented 11 months ago

Error: Bindings not found is emitted by SWC (a very fast TypeScript compiler written in Rust) when it fails to find and load its native library counterpart. This is almost always due to the fact that you ran 'npm i' (or equivalent) from one execution context (e.g. from a OSX terminal using a M1 build of node) but then run your test in a different execution context (e.g. running tests through docker or a x64 build of node).

Simply running npm i from the target execution environment is generally sufficient to resolve that issue, but it some cases, you may need to delete all of your node_modules directories, then run npm -i again.

You may also try the following command to find out which SWC bindings packages are currently installed:

find . -name '@swc' -exec 'ls' '-l' '{}' ';'

Compare that list to the output of the following command:

node -e 'console.log(`${process.platform}-${process.arch}`)'
redpanda commented 11 months ago

Hello @mjameswh,

Thanks for your feedback.

Despite deleting the node_modules folder and reinstalling the packages, I still had the bindings problem. I also ran the two commands concerning SWC bindings packages and got the same thing: core-darwin-x64.

However, I managed to fix the error by installing @swc/cli and @swc/core at the root of the project based on this GitHub issue. But I'm not sure I should do something like that... 😅

I'll re-run some tests in a Docker container.

mjameswh commented 9 months ago

Closing as OP found a solution, and I can't repro.