Compatibility flags for PosgreSQL

I am trying to build and deploy SvelteKit page with enabled flags: nodejs_compat or nodejs_compat_v2 https://developers.cloudflare.com/workers/configuration/compatibility-dates/#compatibility-flags I am using Drizzle connector, but seems I run always into node compatibility issues, which are present on native postgres.js also. Connectors are present in Hyperdrive: https://developers.cloudflare.com/hyperdrive/configuration/connect-to-postgres/#supported-drivers Source code: https://github.com/bchainhub/dapp-sveltekit-boilerplate/tree/update/contrib-13 My questions: Q1: Do I need to upgrade to paid plan for Node.js features support? (I am aware of Hyperdrive included in Paid plan) Q2: What should I change to make Node.js API working on my Pages deployment? Some of errors I am getting while deployment:
✘ [ERROR] Could not resolve "node:stream"
node_modules/postgres/cf/src/large.js:1:import Stream from 'node:stream'
The package "node:stream" 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.

error during build:
Error: Build failed with 8 errors:
node_modules/postgres/cf/polyfills.js:1:29: ERROR: Could not resolve "node:events"
node_modules/postgres/cf/polyfills.js:2:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/bytes.js:1:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/connection.js:1:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/connection.js:6:19: ERROR: Could not resolve "node:stream"
✘ [ERROR] Could not resolve "node:stream"
node_modules/postgres/cf/src/large.js:1:import Stream from 'node:stream'
The package "node:stream" 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.

error during build:
Error: Build failed with 8 errors:
node_modules/postgres/cf/polyfills.js:1:29: ERROR: Could not resolve "node:events"
node_modules/postgres/cf/polyfills.js:2:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/bytes.js:1:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/connection.js:1:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/connection.js:6:19: ERROR: Could not resolve "node:stream"
- page: core-dapp.pages.dev - deployment: 580ce1e I checked the examples here also: https://developers.cloudflare.com/hyperdrive/examples/
17 Replies
vytskalt
vytskalt3mo ago
i just ran into this exact same error (using sveltekit + postgres.js). were you able to resolve it?
Rastislav₡ore
Rastislav₡oreOP3mo ago
@vytskalt so far no solution. Seems this is serious bug on side of Cloudflare. I am trying to resolve with Drizzle ORM but same issues. I will update here if some news will occur. @Community Champion should I report bug? If yes, where?
andrew_nyr
andrew_nyr3mo ago
?pings
Flare
Flare3mo ago
Please do not ping community members for non-moderation reasons. Doing so will not solve your issue faster and will make people less likely to want to help you.
Rastislav₡ore
Rastislav₡oreOP2mo ago
Oh sorry, didn't know. I will found out myself. @vytskalt Sent to support. When I will get any reply, I will reveal solution here. Similar error related for Next.js is here: https://discord.com/channels/595317990191398933/1287862192712192113 One additional note to the topic: - I have paid pages/workers plan - Hyperdrive is available for me No other updates so far about the topic.
Register
Register2mo ago
Im having this exact issue too after implementing svelte, but im not using sveltekit
⛅️ wrangler 3.79.0
-------------------

X [ERROR] Could not resolve "@base/ResponseCode"

api/playground/token.ts:2:29:
2 │ import { ResponseCode } from "@base/ResponseCode";
╵ ~~~~~~~~~~~~~~~~~~~~

You can mark the path "@base/ResponseCode" as external to exclude it from the bundle, which will remove this error.



X [ERROR] Failed to build Functions at ./functions.
⛅️ wrangler 3.79.0
-------------------

X [ERROR] Could not resolve "@base/ResponseCode"

api/playground/token.ts:2:29:
2 │ import { ResponseCode } from "@base/ResponseCode";
╵ ~~~~~~~~~~~~~~~~~~~~

You can mark the path "@base/ResponseCode" as external to exclude it from the bundle, which will remove this error.



X [ERROR] Failed to build Functions at ./functions.
My ResponseCode.ts
export enum ResponseCode {
OK = 200,
Created = 201,
NoContent = 204,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
MethodNotAllowed = 405,
Conflict = 409,
InternalServerError = 500,
NotImplemented = 501,
BadGateway = 502,
ServiceUnavailable = 503,
}
export enum ResponseCode {
OK = 200,
Created = 201,
NoContent = 204,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
MethodNotAllowed = 405,
Conflict = 409,
InternalServerError = 500,
NotImplemented = 501,
BadGateway = 502,
ServiceUnavailable = 503,
}
and the token.ts file thats throwing the error
import EventContext from "@base/EventContext";
import { ResponseCode } from "@base/ResponseCode";
import { ChaCha20Poly1305 } from "@stablelib/chacha20poly1305";
import { randomBytes } from "@stablelib/random";
import EventContext from "@base/EventContext";
import { ResponseCode } from "@base/ResponseCode";
import { ChaCha20Poly1305 } from "@stablelib/chacha20poly1305";
import { randomBytes } from "@stablelib/random";
It specifically targets the ResponseCode.ts file for some reason and I have no idea why EventContext.ts is in the same directory as @base
Rastislav₡ore
Rastislav₡oreOP2mo ago
I think the issue is not related to framework, because I am aware of issues for React also. You may be in same category as us. I am still waiting for support team to answer. Seems no really priority to them. I will recommend you will raise support ticket as well, it may be faster answer for you. I will appreciate sharing any feedback from you @Register Thank you for contributing to thread.
Register
Register2mo ago
Actually we fixed it
Register
Register2mo ago
It was an issue with our tsconfig
No description
Rastislav₡ore
Rastislav₡oreOP2mo ago
Reply from the Cloudflare support: Please consider the following recommendations: 1. Change the NODE_VERSION to v18. 2. Set the compatibility date to the current date.
Register
Register3w ago
Did it work?
Rastislav₡ore
Rastislav₡oreOP3w ago
@Register Not at all. Mr. Sugar (Account Manager) has acknowledged the issues and malfunctioning services Cloudflare provides, with no resolution in sight. I strongly recommend discontinuing Cloudflare services where feasible. Our team is currently migrating away due to their persistent technical incompetence and lack of professional reliability.
Register
Register3w ago
Yeah I've certainly had my own issues but I did overcome them.
Rastislav₡ore
Rastislav₡oreOP3w ago
Currently the Cloudflare's bug is not possible to resolve. There is malfunction in Hyperdrive and D1, I will not recommend to use it even in future because my experiences with Cloudflare's development team. Internal processes were failing. But if you want to do some development possible, please not production. I am currently removing anything related to Cloudflare in our application. I received new recommendation as: - do not use auto-adapter (BTW this is not working for me either) svelte.config.js
import adapter from '@sveltejs/adapter-cloudflare';

export default {
kit: {
adapter: adapter({
// See below for an explanation of these options
routes: {
include: ['/*'],
exclude: ['<all>']
},
platformProxy: {
configPath: 'wrangler.toml',
environment: undefined,
experimentalJsonConfig: false,
persist: false
}
})
}
};
import adapter from '@sveltejs/adapter-cloudflare';

export default {
kit: {
adapter: adapter({
// See below for an explanation of these options
routes: {
include: ['/*'],
exclude: ['<all>']
},
platformProxy: {
configPath: 'wrangler.toml',
environment: undefined,
experimentalJsonConfig: false,
persist: false
}
})
}
};
wrangler.toml
pages_build_output_dir = ".svelte-kit/cloudflare"
pages_build_output_dir = ".svelte-kit/cloudflare"
None of those is helping me. And after discussion with SvelteKit developer community not recommended either.
ruthenz.
ruthenz.3w ago
I feel like I'm experiencing the same thing... Trying to use "pg" (https://www.npmjs.com/package/pg) with RemixJS and getting this errors on build : - The package "stream" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your Pages project and make sure to prefix the module name with "node:" to enable Node.js compatibility. - ../node_modules/.pnpm/[email protected]/node_modules/pg-cloudflare/dist/index.js:1:29: ERROR: Could not resolve "events" And I tried searching the web for hours without finding any real answer on how to solve this. Is this really this big of an issue? how does anyone use postgres without Hyperdrive on Cloudflare? What am I missing?
npm
pg
PostgreSQL client - pure javascript & libpq with the same API. Latest version: 8.13.1, last published: 11 days ago. Start using pg in your project by running npm i pg. There are 10245 other projects in the npm registry using pg.
Mathew
Mathew3w ago
hi folks - were you guys able to get the deploy working?
ruthenz.
ruthenz.2w ago
I didn’t
Want results from more Discord servers?
Add your server