Error when trying to build project in Cloudflare

So I'm having the following error when trying to build the project in cloudflare:
error during build:
17:19:52.767 [vite]: Rollup failed to resolve import "zod" from "/opt/buildhome/repo/api/shared/expenses.types.ts".
17:19:52.767 This is most likely unintended because it can break your application at runtime.
17:19:52.767 If you do want to externalize this module explicitly add it to
17:19:52.767 `build.rollupOptions.external`
17:19:52.767 at viteWarn (/opt/buildhome/repo/web/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:51043:21)
17:19:52.768 at onwarn (/opt/buildhome/repo/web/node_modules/@vitejs/plugin-react/dist/index.mjs:282:9)
17:19:52.768 at onRollupWarning (/opt/buildhome/repo/web/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:51073:5)
17:19:52.768 at onwarn (/opt/buildhome/repo/web/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:50741:7)
17:19:52.768 at <anonymous> (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:19599:13)
17:19:52.768 at logger (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:21325:9)
17:19:52.768 at handleInvalidResolvedId (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:20214:26)
17:19:52.768 at <anonymous> (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:20172:26)
17:19:52.768 at processTicksAndRejections (native:7:39)
17:19:52.786 error: script "build" exited with code 1
17:19:52.789 Failed: Error while executing user command. Exited with error code: 1
17:19:52.797 Failed: build command exited with code: 1
17:19:53.644 Failed: error occurred while running build command
error during build:
17:19:52.767 [vite]: Rollup failed to resolve import "zod" from "/opt/buildhome/repo/api/shared/expenses.types.ts".
17:19:52.767 This is most likely unintended because it can break your application at runtime.
17:19:52.767 If you do want to externalize this module explicitly add it to
17:19:52.767 `build.rollupOptions.external`
17:19:52.767 at viteWarn (/opt/buildhome/repo/web/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:51043:21)
17:19:52.768 at onwarn (/opt/buildhome/repo/web/node_modules/@vitejs/plugin-react/dist/index.mjs:282:9)
17:19:52.768 at onRollupWarning (/opt/buildhome/repo/web/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:51073:5)
17:19:52.768 at onwarn (/opt/buildhome/repo/web/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:50741:7)
17:19:52.768 at <anonymous> (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:19599:13)
17:19:52.768 at logger (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:21325:9)
17:19:52.768 at handleInvalidResolvedId (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:20214:26)
17:19:52.768 at <anonymous> (/opt/buildhome/repo/web/node_modules/rollup/dist/es/shared/node-entry.js:20172:26)
17:19:52.768 at processTicksAndRejections (native:7:39)
17:19:52.786 error: script "build" exited with code 1
17:19:52.789 Failed: Error while executing user command. Exited with error code: 1
17:19:52.797 Failed: build command exited with code: 1
17:19:53.644 Failed: error occurred while running build command
1 Reply
Amodeus R.
Amodeus R.OP3w ago
I tried doing what was suggested by the error, but when I try it another error happens, but in the frontend Uncaught TypeError: Failed to resolve module specifier "zod". Relative references must start with either "/", "./", or "../"., and it doesn't show anything in the page. When I build the project locally with the rollupOptions it also throws the same error, but it works fine without it locally. I believe it has something to do with the way the project is structured, since it's a monorepo with the backend in another website, while the frontend is in Cloudflare, and I'm trying to import some zod schemas from the backend to the frontend. If there's any utility in seing the folder structure, you can see the github repo here. How can I solve this problem and make the frontend work?

Did you find this page helpful?