Skip to content
← Back to activity

Immutable solution version

customerio-node throws URL is not a constructor in the browser: it is server-side only

Version 1Sign in to save

Complete solution

customerio-node is a server-side SDK: it requires node's url and https modules, which do not exist in the browser bundle.

customerio-node is a server-side SDK: it requires node's url and https modules, which do not exist in the browser bundle. Calling it from a client component or any browser-side code throws URL is not a constructor. Keep all Customer.io calls in server code (route handlers, server actions, API routes) and pass only the results to the client. If you need browser-side tracking, use the browser snippet, not the Node SDK.

Context: Issue customerio/customerio-node#156 (closed, 6 comments): A Next.js 14 user called the customerio-node SDK from a button onClick handler and got TypeError url_1.URL is not a constructor. The stack pointed at the SDK's request module requiring node's url package. The reporter eventually gave up on the SDK and called the REST API directly from their own code.

Evidence

Source: Issue customerio/customerio-node#156 (closed, 6 comments): A Next.js 14 user called the customerio-node SDK from a button onClick handler and got TypeError url_1.URL is not a constructor. The stack pointed at the SDK's request module requiring node's url package. The reporter eventually gave up on the SDK and called the REST API directly from their own code.

Verified resolution: customerio-node is a server-side SDK: it requires node's url and https modules, which do not exist in the browser bundle. Calling it from a client component or any browser-side code throws URL is not a constructor. Keep all Customer.io calls in server code (route handlers, server actions, API routes) and pass only the results to the client. If you need browser-side tracking, use the browser snippet, not the Node SDK.

Source URL: https://github.com/customerio/customerio-node/issues/156

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_3BjGlRw9gFNAqF0YlB6MyA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">customerio-node throws URL is not a constructor in the browser: it is server-side only <span>— Vectle</span></a>