Webpack doesnt include node.js polyfills

This is a weird one.
I am running temporal inside of an NX monorepo and i have everything running okay at the moment.

Now i am trying to get everything running inside docker and i keep running into webpack build errors about polyfills

2022-08-26T21:33:35.952Z [ERROR] ERROR in ./node_modules/webpack/lib/util/identifier.js 7:13-28
2022-08-26T21:33:35.952Z [ERROR] Module not found: Error: Can't resolve 'path' in '/app/node_modules/webpack/lib/util'
2022-08-26T21:33:35.952Z [ERROR] 
2022-08-26T21:33:35.952Z [ERROR] BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
2022-08-26T21:33:35.952Z [ERROR] This is no longer the case. Verify if you need this module and configure a polyfill for it.
2022-08-26T21:33:35.952Z [ERROR] 
2022-08-26T21:33:35.952Z [ERROR] If you want to include a polyfill, you need to:
2022-08-26T21:33:35.952Z [ERROR]        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
2022-08-26T21:33:35.952Z [ERROR]        - install 'path-browserify'
2022-08-26T21:33:35.952Z [ERROR] If you don't want to include a polyfill, you can use an empty module like this:
2022-08-26T21:33:35.952Z [ERROR]        resolve.fallback: { "path": false }
2022-08-26T21:33:35.952Z [ERROR]  @ ./node_modules/webpack/lib/DllReferencePlugin.js 14:26-72
2022-08-26T21:33:35.952Z [ERROR]  @ ./node_modules/webpack/lib/index.js 180:9-40
2022-08-26T21:33:35.952Z [ERROR]  @ ./node_modules/@temporalio/worker/lib/workflow/bundler.js 29:34-52
2022-08-26T21:33:35.952Z [ERROR]  @ ./node_modules/@temporalio/worker/lib/index.js 32:16-45
2022-08-26T21:33:35.952Z [ERROR]  @ ./node_modules/nestjs-temporal/dist/temporal.explorer.js 26:17-46
2022-08-26T21:33:35.952Z [ERROR]  @ ./node_modules/nestjs-temporal/dist/index.js 14:13-43
2022-08-26T21:33:35.952Z [ERROR]  @ ./src/app/app.module.js 5:26-52
2022-08-26T21:33:35.952Z [ERROR]  @ ./src/main.js 11:21-48

Im trying to think of the question i need to ask here, but it seems that once i get the code into the docker container that the worker.create method isnt just compiling my workflow code its trying to rerun all the files.

I jumped into the docker container and checked that the workflowsPath only contained the workflow code and that seems to be accurate.

I am going to try and spend some time creating a repo that encompasses this, but it might take a while

Hi :wave:

You can’t use Node.js modules in workflow code since they might break the deterministic nature of the runtime.

I am using xstate in the workflow to do finite state machines but I am not using anything that would break determinism

Also this works currently, just not when run inside a docker container

What executor are you using in prod? It needs to be one that runs code in node, like this one:

https://community.temporal.io/t/using-temporal-with-nx-monorepo/5228/4

Yeah right now I’m using the @nrwl/js:tsc

We need to get your workflow bundle to not require path. Any idea why path would be part of the bundle (ie required by some code that’s required by worklow code) in prod but not dev?

Also, what version of @temporalio/worker are you on? I’d think you should get this message that @mjameswh added:

From your log above, it appears that, for some reason, the workflow bundler is actually trying to bundle your src/main.js file, which eventually cause the inclusion of nestjs-temporal, then @temporalio/worker, and eventually webpack. That is, the bundler is trying to bundle itself. That’s never a good thing.

Could you please specify which versions of nestjs-temporal and @temporalio/worker you are using. Also, it would help if you could share the configuration code of your Temporal module (likely in app.module.ts).

And one last thing… You mentioned that you are using a monorepo… Are your workflows in a distinct package from your worker code? Are you using some type of package aliases between these packages?

Sorry didnt respond earlier, i tried lots of things and must have somehow arrived at the answer above about it trying to pull in the main.js file.

Everything is working now, but i dont know how to pinpoint exactly what i did besides just trial and error for a few days

Do you have a full example in git?