PostHog / posthog-node

Official PostHog Node library
MIT License
21 stars 19 forks source link

Does not work on the edge [Cloudflare Pages] #81

Closed marchellodev closed 1 year ago

marchellodev commented 1 year ago

Hello, I am trying to use posthog-node on the backend of Cloudflare pages. This is the log I get when Cloudflare tries to build my app for its environment:

14:17:38.143 | > Using @sveltejs/adapter-cloudflare
14:17:38.260 | ✘ [ERROR] Could not resolve "crypto"
14:17:38.260 |  
14:17:38.260 | node_modules/posthog-node/lib/index.esm.js:1:27:
14:17:38.260 | 1 │ import { createHash } from 'crypto';
14:17:38.260 | ╵                            ~~~~~~~~
14:17:38.260 |  
14:17:38.260 | The package "crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.261 |  
14:17:38.292 | ✘ [ERROR] Could not resolve "https"
14:17:38.292 |  
14:17:38.293 | node_modules/gaxios/build/src/gaxios.js:20:24:
14:17:38.293 | 20 │ const https_1 = require("https");
14:17:38.293 | ╵                         ~~~~~~~
14:17:38.293 |  
14:17:38.293 | The package "https" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.293 |  
14:17:38.294 | ✘ [ERROR] Could not resolve "querystring"
14:17:38.294 |  
14:17:38.294 | node_modules/gaxios/build/src/gaxios.js:22:46:
14:17:38.294 | 22 │ const querystring_1 = __importDefault(require("querystring"));
14:17:38.294 | ╵                                               ~~~~~~~~~~~~~
14:17:38.294 |  
14:17:38.294 | The package "querystring" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.295 |  
14:17:38.302 | ✘ [ERROR] Could not resolve "url"
14:17:38.302 |  
14:17:38.303 | node_modules/gaxios/build/src/gaxios.js:24:22:
14:17:38.303 | 24 │ const url_1 = require("url");
14:17:38.303 | ╵                       ~~~~~
14:17:38.303 |  
14:17:38.303 | The package "url" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.303 |  
14:17:38.318 | ✘ [ERROR] Could not resolve "net"
14:17:38.318 |  
14:17:38.319 | node_modules/https-proxy-agent/dist/agent.js:15:38:
14:17:38.319 | 15 │ const net_1 = __importDefault(require("net"));
14:17:38.320 | ╵                                       ~~~~~
14:17:38.320 |  
14:17:38.320 | The package "net" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.320 |  
14:17:38.321 | ✘ [ERROR] Could not resolve "tls"
14:17:38.321 |  
14:17:38.321 | node_modules/https-proxy-agent/dist/agent.js:16:38:
14:17:38.321 | 16 │ const tls_1 = __importDefault(require("tls"));
14:17:38.321 | ╵                                       ~~~~~
14:17:38.321 |  
14:17:38.321 | The package "tls" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.322 |  
14:17:38.322 | ✘ [ERROR] Could not resolve "url"
14:17:38.322 |  
14:17:38.322 | node_modules/https-proxy-agent/dist/agent.js:17:38:
14:17:38.322 | 17 │ const url_1 = __importDefault(require("url"));
14:17:38.322 | ╵                                       ~~~~~
14:17:38.322 |  
14:17:38.322 | The package "url" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.323 |  
14:17:38.323 | ✘ [ERROR] Could not resolve "assert"
14:17:38.323 |  
14:17:38.324 | node_modules/https-proxy-agent/dist/agent.js:18:41:
14:17:38.324 | 18 │ const assert_1 = __importDefault(require("assert"));
14:17:38.324 | ╵                                          ~~~~~~~~
14:17:38.324 |  
14:17:38.324 | The package "assert" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.324 |  
14:17:38.325 | ✘ [ERROR] Could not resolve "events"
14:17:38.325 |  
14:17:38.325 | node_modules/agent-base/dist/src/index.js:5:25:
14:17:38.325 | 5 │ const events_1 = require("events");
14:17:38.325 | ╵                          ~~~~~~~~
14:17:38.325 |  
14:17:38.326 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
14:17:38.326 |  
14:17:38.338 | error during build:
14:17:38.338 | Error: Build failed with 9 errors:
14:17:38.338 | node_modules/agent-base/dist/src/index.js:5:25: ERROR: Could not resolve "events"
14:17:38.338 | node_modules/gaxios/build/src/gaxios.js:20:24: ERROR: Could not resolve "https"
14:17:38.339 | node_modules/gaxios/build/src/gaxios.js:22:46: ERROR: Could not resolve "querystring"
14:17:38.339 | node_modules/gaxios/build/src/gaxios.js:24:22: ERROR: Could not resolve "url"
14:17:38.339 | node_modules/https-proxy-agent/dist/agent.js:15:38: ERROR: Could not resolve "net"
14:17:38.339 | ...
14:17:38.339 | at failureErrorWithLog (/opt/buildhome/repo/node_modules/esbuild/lib/main.js:1604:15)
14:17:38.339 | at /opt/buildhome/repo/node_modules/esbuild/lib/main.js:1056:28
14:17:38.339 | at /opt/buildhome/repo/node_modules/esbuild/lib/main.js:1001:67
14:17:38.339 | at buildResponseToResult (/opt/buildhome/repo/node_modules/esbuild/lib/main.js:1054:7)
14:17:38.339 | at /opt/buildhome/repo/node_modules/esbuild/lib/main.js:1166:14
14:17:38.340 | at responseCallbacks.<computed> (/opt/buildhome/repo/node_modules/esbuild/lib/main.js:701:9)
14:17:38.340 | at handleIncomingPacket (/opt/buildhome/repo/node_modules/esbuild/lib/main.js:756:9)
14:17:38.340 | at Socket.readFromStdout (/opt/buildhome/repo/node_modules/esbuild/lib/main.js:677:7)
14:17:38.340 | at Socket.emit (node:events:513:28)
14:17:38.340 | at addChunk (node:internal/streams/readable:315:12)
14:17:38.369 | Failed: build command exited with code: 1
14:17:39.276 | Failed: an internal error occurred
marchellodev commented 1 year ago

Sorry. Moved to the new version https://github.com/PostHog/posthog-js-lite/issues/67