Tanstack Start cannot use server-only package pub-sub-api-node-client in production
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Start
Describe the bug
The pub-sub-api-node-client library (intended for backend/server only) works fine in development, but fails at runtime when bundled with nitro for docker deployment.
The author of the library suggested that it might be because of the bundling process:
Main issues are the library's cert file not being found, and fs being null (but only in the context of the @grpc/grpc-js's proto-loader package).
Your Example Website or App
https://github.com/nktnet-bug-report/sf-pubsub-api-test
Steps to Reproduce the Bug or Issue
Same instructions as listed in the README.md of the minimal reproducible example:
click to view
Setup
pnpm install
cp .env.example .env
Set up env as per ./.env.example
Development
pnpm dev
Click on the green "Salesforce Pubsub Test" button or go to http://localhost:3000/sf-pubsub
Observe that there are no errors.
Production
Install the dotenv CLI tool is install to read from .env.
Bug 1 - no such file (cert)
Error: ENOENT: no such file or directory, open '/path/.output/server/_libs/cacert-2ebcb9e8.pem'
pnpm build && dotenv -f .env run node .output/server/index.mjs
Bug 2 - fs is null
TypeError: Cannot read properties of null (reading 'readFileSync')
pnpm build && cp ./node_modules/salesforce-pubsub-api-client/dist/*.pem .output/server/_libs/ && dotenv -f .env run node .output/server/index.mjs
Expected behavior
It should work in production without runtime errors, just like in development.
Platform
- Router / Start Version: [e.g. 1.132.0]
- OS: macOS, Linux
- Browser: Zen
- Browser Version: 1.17.15b
- Bundler: vite
- Bundler Version: 7.1.7
Additional context
Original issue:
When using Next.JS, the library works fine (with a small hiccup where I needed to use turbopackMinify: false).
Also cross-posted here (not sure if it's a nitro issue or tanstack start issue):
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction project's README.md and .env.example, then run the listed pnpm dev and pnpm build commands. Inspect .output/server/index.mjs and the generated _libs directory around the certificate and fs errors, comparing development with the production bundle. Done means the production command runs without either runtime error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript, vite
- Domain
- backend, build-system, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100