Debugging Script startup exceeded CPU time limit.

Hi, I'm using remix on cloudflare pages, when I try deploying I get - Error: Failed to publish your Function. Got error: Error: Script startup exceeded CPU time limit. Seems like a common issue with pages and workers, but I haven't found a good way to debug this other than making heavy imports async. Its not clear what might be the heavy import in my application since my server bundle is 163K, any pointers on how I can debug this further? Is there a way to investigate startup time locally. I'm using note compatibility for remix-auth-totp, but nothing else that happens in global context. I'm also using R2, D1, and KV.
4 Replies
squareclamp
squareclampOP9mo ago
Maybe this is the problem, while build/server/index.js is 163K. When I run npm start, the worker files are lot bigger. -
./.wrangler/tmp/bundle-opZdrn:
total 24
drwx------ 5 squareclamp staff 160B Mar 16 09:55 .
drwxr-xr-x 6 squareclamp staff 192B Mar 16 09:55 ..
-rw-r--r-- 1 squareclamp staff 834B Mar 16 09:55 checked-fetch.js
-rw-r--r-- 1 squareclamp staff 1.2K Mar 16 09:55 middleware-insertion-facade.js
-rw-r--r-- 1 squareclamp staff 4.0K Mar 16 09:55 middleware-loader.entry.ts

./.wrangler/tmp/dev-slWMRR:
total 52272
drwx------ 4 squareclamp staff 128B Mar 16 09:55 .
drwxr-xr-x 6 squareclamp staff 192B Mar 16 09:55 ..
-rw-r--r-- 1 squareclamp staff 9.4M Mar 16 09:55 functionsWorker-0.9742302954182822.js
-rw-r--r-- 1 squareclamp staff 16M Mar 16 09:55 functionsWorker-0.9742302954182822.js.map

./.wrangler/tmp/pages-4LxuuY:
total 52936
drwx------ 5 squareclamp staff 160B Mar 16 09:55 .
drwxr-xr-x 6 squareclamp staff 192B Mar 16 09:55 ..
-rw-r--r-- 1 squareclamp staff 299B Mar 16 09:55 functionsRoutes-0.20111918050431377.mjs
-rw-r--r-- 1 squareclamp staff 9.4M Mar 16 09:55 functionsWorker-0.9742302954182822.mjs
-rw-r--r-- 1 squareclamp staff 16M Mar 16 09:55 functionsWorker-0.9742302954182822.mjs.map
./.wrangler/tmp/bundle-opZdrn:
total 24
drwx------ 5 squareclamp staff 160B Mar 16 09:55 .
drwxr-xr-x 6 squareclamp staff 192B Mar 16 09:55 ..
-rw-r--r-- 1 squareclamp staff 834B Mar 16 09:55 checked-fetch.js
-rw-r--r-- 1 squareclamp staff 1.2K Mar 16 09:55 middleware-insertion-facade.js
-rw-r--r-- 1 squareclamp staff 4.0K Mar 16 09:55 middleware-loader.entry.ts

./.wrangler/tmp/dev-slWMRR:
total 52272
drwx------ 4 squareclamp staff 128B Mar 16 09:55 .
drwxr-xr-x 6 squareclamp staff 192B Mar 16 09:55 ..
-rw-r--r-- 1 squareclamp staff 9.4M Mar 16 09:55 functionsWorker-0.9742302954182822.js
-rw-r--r-- 1 squareclamp staff 16M Mar 16 09:55 functionsWorker-0.9742302954182822.js.map

./.wrangler/tmp/pages-4LxuuY:
total 52936
drwx------ 5 squareclamp staff 160B Mar 16 09:55 .
drwxr-xr-x 6 squareclamp staff 192B Mar 16 09:55 ..
-rw-r--r-- 1 squareclamp staff 299B Mar 16 09:55 functionsRoutes-0.20111918050431377.mjs
-rw-r--r-- 1 squareclamp staff 9.4M Mar 16 09:55 functionsWorker-0.9742302954182822.mjs
-rw-r--r-- 1 squareclamp staff 16M Mar 16 09:55 functionsWorker-0.9742302954182822.mjs.map
I remove some packages, brought it down to < 1MB gzipped. And now I see Error: Failed to publish your Function. Got error: Unknown internal error occurred.
bloushi
bloushi8mo ago
Hi @squareclamp Were you able to fix this issue? I am facing similar problems when trying to move my Pages project to vite. My project deploys without any issues using the old build system, but the vite project keeps giving me the following error:
Error: Failed to publish your Function. Got error: Error: Script startup exceeded CPU time limit.
Error: Failed to publish your Function. Got error: Error: Script startup exceeded CPU time limit.
Following is my vite config:
export default defineConfig({
plugins: [
remixCloudflareDevProxy({ getLoadContext }),
remix({
ignoredRouteFiles: ["**/*.css"],
}),
tsconfigPaths(),
],
assetsInclude: ["**/*.md"],
ssr: {
noExternal: [],
optimizeDeps: {
// exclude: ["bcryptjs"],
},
target: "webworker",
resolve: {
conditions: ["workerd", "worker", "import", "module", "browser", "default"],
},
},
build: {
minify: "esbuild",
},
});
export default defineConfig({
plugins: [
remixCloudflareDevProxy({ getLoadContext }),
remix({
ignoredRouteFiles: ["**/*.css"],
}),
tsconfigPaths(),
],
assetsInclude: ["**/*.md"],
ssr: {
noExternal: [],
optimizeDeps: {
// exclude: ["bcryptjs"],
},
target: "webworker",
resolve: {
conditions: ["workerd", "worker", "import", "module", "browser", "default"],
},
},
build: {
minify: "esbuild",
},
});
Any hints on how you were able to get around this issue? Thanks.
squareclamp
squareclampOP8mo ago
Try reducing your bundle size. You can use the following command to see your bundle size. - npx wrangler deploy .wrangler/bundle-analysis/index.js --dry-run --name foo --minify
bloushi
bloushi8mo ago
Cool, will try that. Thanks
Want results from more Discord servers?
Add your server