Skip to content

Tanstack Start cannot use server-only package pub-sub-api-node-client in production #6450

@nktnet1

Description

@nktnet1

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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions