Pages functions advanced mode help

I want to merge my worker with a pages application using functions. I've read the docs and i'm still not sure how to structure the app/ how it works. So _workers.ts needs to be compiled into dist? How do I set this up using the configs, I have three. tsconfig.json, tsconfig.node.json and tsconfig.app.json. I had a go myself but when building I get " error TS6200: Definitions of the following identifiers conflict with those in another file"
No description
4 Replies
JammyG
JammyGOP2w ago
ok, I made this
// tsconfig.worker.json
{
"extends": "./tsconfig.node.json",
"compilerOptions": {
"moduleResolution": "nodenext",
"module": "NodeNext",
"target": "es2022",
"noEmit": false,
"outDir": "./dist",
"allowImportingTsExtensions": false,
"types": [
"@cloudflare/workers-types"
]
},
"include": [
"worker-src"
]
}
// tsconfig.worker.json
{
"extends": "./tsconfig.node.json",
"compilerOptions": {
"moduleResolution": "nodenext",
"module": "NodeNext",
"target": "es2022",
"noEmit": false,
"outDir": "./dist",
"allowImportingTsExtensions": false,
"types": [
"@cloudflare/workers-types"
]
},
"include": [
"worker-src"
]
}
now when I run build it outputs a _worker.js file into /dist But it's not being picked up by Pages
JammyG
JammyGOP2w ago
No description
JammyG
JammyGOP2w ago
No description
JammyG
JammyGOP2w ago
when i run npm run build locally, the _worker.js file is output to dist. But I can't see the file in my actual deployment, and no functions are being created either. Okay it's working now, I wish there was a bit more documentation on Advanced mode. The default package.json generated by wrangler runs:
"build": "tsc -b && vite build"
"build": "tsc -b && vite build"
Which builds the _worker.ts file, but is then immediatley deleted by vite
"build": "vite build && tsc -b"
"build": "vite build && tsc -b"
Flipping them around fixes it (I think) I hope this doesn't cause some weird behaviour . How do I handle using secrets and types in Advanced mode? running wrangler types generates types for my DB and secrets
// Generated by Wrangler by running `wrangler types`

interface Env {
SECRET_KEY: string;
DB: D1Database;
}
// Generated by Wrangler by running `wrangler types`

interface Env {
SECRET_KEY: string;
DB: D1Database;
}
but it deletes the interface I need for
interface Env {
ASSETS: Fetcher;
}
interface Env {
ASSETS: Fetcher;
}
Every time i run it which makes me think i'm doing something wrong. Also when I try to put my secrets using wrangler, it tells me I dont have a worker and suggests creating one. Any advice on this would be appreciated.

Did you find this page helpful?