sdk-typescript icon indicating copy to clipboard operation
sdk-typescript copied to clipboard

[Feature Request] pnpm support

Open mengyazhu96 opened this issue 5 years ago • 18 comments

Is your feature request related to a problem? Please describe.

When using pnpm with the Typescript SDK, the Temporal worker's webpack building step fails. As a workaround, we had to add the shamefully-hoist=true option so that pnpm reverts to npm/yarn style module locations, e.g. putting everything in ./node_modules instead of in workspace node modules, e.g. ./workspaces/*/node_modules

Describe the solution you'd like

Support pnpm. I'm not sure what this entails 😅

Additional context

From Slack thread here: https://temporalio.slack.com/archives/C01DKSMU94L/p1638764279342400

cc @bergundy @spikebrehm

mengyazhu96 avatar Dec 06 '21 17:12 mengyazhu96

There may be multiple layers of issues, but the immediate one that surfaces has to do with missing dependencies listed in your monorepo packages' package.json. For example, grep for protobufjs; you’ll note that it’s listed in packages/worker/package.json but is only used in the packages/workflow package, and not listed in its package.json. probably a mistake during refactoring. That's the first example that errored for us but there may be more issues like this in your monorepo.

Relatedly, this is why we moved from npm -> pnpm — it fails loudly when packages/workspaces haven’t configured dependencies correctly.

spikebrehm avatar Dec 07 '21 14:12 spikebrehm

@mengyazhu96 I'm unable to get it working even with shamefully-hoist=true. Was there anything else you had to do?

2021-12-09T18:25:30.281Z [ERROR] ERROR in ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/common/lib/time.js 7:31-46
2021-12-09T18:25:30.281Z [ERROR] Module not found: Error: Can't resolve 'long' in '/Users/b/c/flightcontrol/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/common/lib'
2021-12-09T18:25:30.281Z [ERROR]  @ ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/common/lib/index.js 24:13-30
2021-12-09T18:25:30.281Z [ERROR]  @ ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib/worker-interface.js 9:17-46
2021-12-09T18:25:30.281Z [ERROR]  @ ../../../../../../src/main.js 1:0-68 4:0-19 5:0-18 26:4-7
2021-12-09T18:25:30.281Z [ERROR]
2021-12-09T18:25:30.281Z [ERROR] ERROR in ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/common/lib/time.js 8:29-42
2021-12-09T18:25:30.281Z [ERROR] Module not found: Error: Can't resolve 'ms' in '/Users/b/c/flightcontrol/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/common/lib'
2021-12-09T18:25:30.281Z [ERROR]  @ ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/common/lib/index.js 24:13-30
2021-12-09T18:25:30.281Z [ERROR]  @ ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib/worker-interface.js 9:17-46
2021-12-09T18:25:30.281Z [ERROR]  @ ../../../../../../src/main.js 1:0-68 4:0-19 5:0-18 26:4-7
2021-12-09T18:25:30.281Z [ERROR]
2021-12-09T18:25:30.281Z [ERROR] ERROR in ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/proto/lib/coresdk.js 4:16-45
2021-12-09T18:25:30.281Z [ERROR] Module not found: Error: Can't resolve 'protobufjs/minimal' in '/Users/b/c/flightcontrol/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/proto/lib'
2021-12-09T18:25:30.281Z [ERROR]  @ ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib/worker-interface.js 10:18-58
2021-12-09T18:25:30.281Z [ERROR]  @ ../../../../../../src/main.js 1:0-68 4:0-19 5:0-18 26:4-7
2021-12-09T18:25:30.281Z [ERROR]
2021-12-09T18:25:30.281Z [ERROR] ERROR in ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib/internals.js 38:31-46
2021-12-09T18:25:30.281Z [ERROR] Module not found: Error: Can't resolve 'long' in '/Users/b/c/flightcontrol/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib'
2021-12-09T18:25:30.281Z [ERROR]  @ ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib/worker-interface.js 11:20-42
2021-12-09T18:25:30.281Z [ERROR]  @ ../../../../../../src/main.js 1:0-68 4:0-19 5:0-18 26:4-7
2021-12-09T18:25:30.281Z [ERROR]
2021-12-09T18:25:30.281Z [ERROR] ERROR in ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib/internals.js 39:32-61
2021-12-09T18:25:30.281Z [ERROR] Module not found: Error: Can't resolve 'protobufjs/minimal' in '/Users/b/c/flightcontrol/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib'
2021-12-09T18:25:30.281Z [ERROR]  @ ../../node_modules/.pnpm/@[email protected]/node_modules/@temporalio/workflow/lib/worker-interface.js 11:20-42
2021-12-09T18:25:30.281Z [ERROR]  @ ../../../../../../src/main.js 1:0-68 4:0-19 5:0-18 26:4-7
2021-12-09T18:25:30.281Z [ERROR]
2021-12-09T18:25:30.281Z [ERROR] 5 errors have detailed information that is not shown.
2021-12-09T18:25:30.281Z [ERROR] Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
2021-12-09T18:25:30.281Z [ERROR]
2021-12-09T18:25:30.281Z [ERROR] webpack 5.65.0 compiled with 5 errors in 4357 ms

flybayer avatar Dec 09 '21 18:12 flybayer

Sounds like all we need is to add the missing dependencies to each package. I think there's some lint rule that checks that any referenced package in your code is referenced in package.json, I'll get to this soon.

bergundy avatar Dec 09 '21 18:12 bergundy

While trying to reproduce this, I got errors that are unrelated to missing dependencies. Even dependencies that are defined properly aren't being found by webpack if I install the packages with pnpm. I'll continue working on it and see what I can find.

bergundy avatar Dec 23 '21 00:12 bergundy

Encountered same issue when trying to setup monorepo with temporal typescript SDK using rushjs.io monorepo approach (which uses pnpm)

akurkin avatar Dec 23 '21 09:12 akurkin

I ended having to add all these dependencies directly to our own workspace, e.g. packages/temporal-worker/package.json in our monorepo:

    "@protobufjs/aspromise": "^1.1.2",
    "@protobufjs/base64": "^1.1.2",
    "@protobufjs/eventemitter": "^1.1.0",
    "@protobufjs/float": "^1.0.2",
    "@protobufjs/inquire": "^1.1.0",
    "@protobufjs/pool": "^1.1.0",
    "@protobufjs/utf8": "^1.1.0",
    "@temporalio/proto": "^0.16.0",
    "long": "^5.2.0",
    "ms": "^2.1.3",
    "protobufjs": "^6.11.2",
    "ts-loader": "^9.2.6",
    "tslib": "^2.3.1",
    "webpack": "^5.20.0",

these instead should be specified as deps in your sdk

spikebrehm avatar Dec 23 '21 15:12 spikebrehm

@spikebrehm what's strange to me is that I'm getting errors for packages that are specified as dependencies. Some of the ones you've posted here are already set as dependencies in the SDK.

bergundy avatar Dec 24 '21 17:12 bergundy

See the pnpm issue here: https://github.com/pnpm/pnpm/issues/4155

bergundy avatar Dec 24 '21 17:12 bergundy

The temporalio@next package still isn't working for me, but the individual packages are working with 0.19.0-rc.1:

git clone [email protected]:temporalio/samples-typescript.git
cd samples-typescript/hello-world
pnpm rm temporalio
pnpm add @temporalio/worker@next @temporalio/workflow@next @temporalio/client@next @temporalio/activity@next
pnpm start
pnpm run workflow

lorensr avatar Mar 04 '22 02:03 lorensr

lets document this! makes sense that the bundle package doesnt work?

swyxio avatar Mar 08 '22 00:03 swyxio

I don't know? I was thinking we'd be able to make it work, and then we won't have anything to document. Haven't looked into it yet

lorensr avatar Mar 08 '22 00:03 lorensr

Looks like pnpm add temporalio doesn't install temporalio's dependencies. I opened an issue, but with 718 open issues, not sure when they'll get to it. Anyone more familiar with pnpm up for taking a look? cc @flybayer

https://github.com/pnpm/pnpm/issues/4428

lorensr avatar Mar 09 '22 21:03 lorensr

Looks like pnpm add temporalio doesn't install temporalio's dependencies.

AFAIK that this is the expected behaviour for pnpm and yarn3. They both impose strict dependency resolution, which means that a package can never get transitive access to dependencies of its own dependencies. If a user package needs to use some library package, it has to name that library package explicitly in its own package.json.

That means that the temporalio meta package simply doesn't make any sense when using pnpm or yarn3. The generic install procedure for these environments should list all temporal public packages explicitly.

I think the only way around this would be to have the meta package reexport the content of all public packages, using package.json's exports field, and have users always import though that meta package. So for example, instead of:

import { proxyActivities } from '@temporalio/workflow';

the user would write:

import { proxyActivities } from 'temporalio/workflow';

mjameswh avatar Mar 14 '22 19:03 mjameswh

Ah, thanks! That makes sense. Looks like Yarn PnP is used by default since v2, and while it works in loose mode, strict mode has been default since v2.1.

lorensr avatar Mar 14 '22 19:03 lorensr

import { proxyActivities } from 'temporalio/workflow';

I have considered this before but I'm not convinced this is the right direction. One of the advantages of having separate packages is that the client does not depend on any native libraries and can be easily used in environments where there's limited control of the deployment process such as serverless functions. We could add aliases from temporalio/* to @temporalio/* but then users that only want the client would need to refactor their imports or include the native library. It would also mean that our docs and samples should reflect these alternative APIs which isn't ideal IMHO. I'm not 100% convinced this would be a real issue, I can be convinced otherwise.

bergundy avatar Mar 14 '22 20:03 bergundy

We could add aliases from temporalio/* to @temporalio/* but then users that only want the client would need to refactor their imports or include the native library. It would also mean that our docs and samples should reflect these alternative APIs which isn't ideal IMHO.

I agree. Officially supporting both syntaxes would mean uncertainties for users. Not desirable.

I'm not 100% convinced this would be a real issue, I can be convinced otherwise.

Don't count on me to convince you, I personally don't think this is an issue either 🤣 Honestly, I only mentioned the alternative for completeness.

mjameswh avatar Mar 14 '22 21:03 mjameswh

Okay then soft plan is to document:

"Don't install the temporalio package if you're using yarn or pnpm. Instead, install the @temporalio/* packages that you import from."

Leaving this issue open for a bit to see if yarn/pnpm users have a different preference or ideas.

lorensr avatar Mar 14 '22 22:03 lorensr

I think it's safe to close this issue. If anyone feels this is not solved, please reopen.

bergundy avatar Apr 21 '22 21:04 bergundy