withastro / adapters

Home for Astro's core maintained adapters
47 stars 26 forks source link

Cannot deploy to Cloudflare Pages / __VUE_PROD_DEVTOOLS__ is not defined #182

Closed npenner closed 3 months ago

npenner commented 4 months ago

Astro Info

Astro                    v4.4.12
Node                     v18.17.1
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/tailwind
                         @astrojs/vue

Describe the Bug

When i try to deploy my project to Cloudflare Pages following the docs the whole build runs fine but when it gets uploaded i get an error from a functionsWorker. Now this might be rather Cloudflare related because the build itself is running fine but i thought i can ask here since i am using the cloudflare adapter which other people use as well and my app is pretty basic. I am using one .vue-Component inside the Astro project.

I am new to Cloudflare pages and this is my first time using server mode / SSR with Astro. This might be a problem of my understanding how this whole thing works.

This is my package.json

{
  "name": "xxx",
  "type": "module",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "astro dev",
    "build": "astro build",
    "preview": "astro preview",
    "astro": "astro",
    "info": "astro info"
  },
  "dependencies": {
    "@astrojs/cloudflare": "^9.1.0",
    "@astrojs/tailwind": "^5.1.0",
    "@astrojs/vue": "^4.0.8",
    "astro": "^4.4.12",
    "astro-heroicons": "^2.1.1",
    "sass": "^1.71.1",
    "tailwindcss": "^3.4.1"
  }
}

And my astro.config.mjs

import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import vue from '@astrojs/vue';
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  output: 'server',
  adapter: cloudflare(),
  integrations: [tailwind(), vue()]
});

I already tried to add different versions of this to the astro config:

vite: {
    define: {
      __VUE_PROD_DEVTOOLS__ :'false',
    }
}
or
vite: {
    define: {
      __VUE_PROD_DEVTOOLS__ :false,
    }
}
or
vite: {
    define: {
      __VUE_PROD_DEVTOOLS__ : JSON.stringify(false),
    }
}

with no success.

This is the cloudflare build protocol:

2024-03-06T08:58:28.726095Z From https://github.com/xxx
2024-03-06T08:58:28.726615Z  * branch            65b26161ae35a82c36d50f58be192f6a09b3885f -> FETCH_HEAD
2024-03-06T08:58:28.726771Z 
2024-03-06T08:58:28.767065Z HEAD is now at 65b2616 updated astro package to 4.4.12
2024-03-06T08:58:28.76764Z  
2024-03-06T08:58:28.861228Z 
2024-03-06T08:58:28.86171Z  Using v2 root directory strategy
2024-03-06T08:58:28.88921Z  Success: Finished cloning repository files
2024-03-06T08:58:29.552754Z Detected the following tools from environment: npm@9.6.7, nodejs@18.17.1
2024-03-06T08:58:29.553491Z Installing project dependencies: npm clean-install --progress=false
2024-03-06T08:58:38.361966Z 
2024-03-06T08:58:38.362204Z added 550 packages, and audited 551 packages in 8s
2024-03-06T08:58:38.362412Z 
2024-03-06T08:58:38.362603Z 195 packages are looking for funding
2024-03-06T08:58:38.362767Z   run `npm fund` for details
2024-03-06T08:58:38.363933Z 
2024-03-06T08:58:38.364109Z found 0 vulnerabilities
2024-03-06T08:58:38.382356Z Executing user command: npm run build
2024-03-06T08:58:38.980884Z 
2024-03-06T08:58:38.981175Z > @example/minimal@0.0.1 build
2024-03-06T08:58:38.981339Z > astro build
2024-03-06T08:58:38.981487Z 
2024-03-06T08:58:40.536147Z 08:58:40 [WARN] [@astrojs/cloudflare] The current configuration does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'noop' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice
2024-03-06T08:58:40.652394Z 08:58:40 [build] output: "server"
2024-03-06T08:58:40.652718Z 08:58:40 [build] directory: /opt/buildhome/repo/dist/
2024-03-06T08:58:40.652911Z 08:58:40 [build] adapter: @astrojs/cloudflare
2024-03-06T08:58:40.653125Z 08:58:40 [build] Collecting build info...
2024-03-06T08:58:40.653646Z 08:58:40 [build] ✓ Completed in 153ms.
2024-03-06T08:58:40.655389Z 08:58:40 [build] Building server entrypoints...
2024-03-06T08:58:59.645459Z 08:58:59 [vite] ✓ built in 18.95s
2024-03-06T08:58:59.645732Z 08:58:59 [build] ✓ Completed in 18.99s.
2024-03-06T08:58:59.64635Z  
2024-03-06T08:58:59.646529Z  building client (vite) 
2024-03-06T08:58:59.654437Z 08:58:59 [vite] transforming...
2024-03-06T08:59:00.14826Z  08:59:00 [vite] ✓ 16 modules transformed.
2024-03-06T08:59:00.179433Z 08:59:00 [vite] rendering chunks...
2024-03-06T08:59:00.207124Z 08:59:00 [vite] computing gzip size...
2024-03-06T08:59:00.212289Z 08:59:00 [vite] dist/_astro/hoisted.3MZjh_vF.js                   0.22 kB │ gzip:  0.16 kB
2024-03-06T08:59:00.212472Z 08:59:00 [vite] dist/_astro/client.JLMMBDNL.js                    0.78 kB │ gzip:  0.51 kB
2024-03-06T08:59:00.212642Z 08:59:00 [vite] dist/_astro/helper.bEWynt9N.js                    1.19 kB │ gzip:  0.55 kB
2024-03-06T08:59:00.212781Z 08:59:00 [vite] dist/_astro/hoisted.klRybzsm.js                   1.42 kB │ gzip:  0.56 kB
2024-03-06T08:59:00.212965Z 08:59:00 [vite] dist/_astro/ChildList.iwknvA-W.js                 5.26 kB │ gzip:  2.24 kB
2024-03-06T08:59:00.213099Z 08:59:00 [vite] dist/_astro/runtime-dom.esm-bundler.qYSWVgeb.js  63.29 kB │ gzip: 25.13 kB
2024-03-06T08:59:00.213234Z 08:59:00 [vite] ✓ built in 562ms
2024-03-06T08:59:00.234565Z 08:59:00 
2024-03-06T08:59:00.234778Z  finalizing server assets 
2024-03-06T08:59:00.235022Z 
2024-03-06T08:59:00.2352Z   08:59:00 [build] Rearranging server assets...
2024-03-06T08:59:00.299113Z 08:59:00 [build] Server built in 19.80s
2024-03-06T08:59:00.299336Z 08:59:00 [build] Complete!
2024-03-06T08:59:00.376673Z Finished
2024-03-06T08:59:00.377421Z Found _worker.js in output directory. Uploading.
2024-03-06T08:59:01.578121Z ✨ Compiled Worker successfully
2024-03-06T08:59:01.634714Z Found _routes.json in output directory. Uploading.
2024-03-06T08:59:01.657346Z Validating asset output directory
2024-03-06T08:59:02.33086Z  Deploying your site to Cloudflare's global network...
2024-03-06T08:59:05.487259Z Uploading... (18/18)
2024-03-06T08:59:05.488316Z ✨ Success! Uploaded 0 files (18 already uploaded) (0.37 sec)
2024-03-06T08:59:05.488519Z 
2024-03-06T08:59:05.824726Z ✨ Upload complete!
2024-03-06T08:59:07.675307Z Success: Assets published!
2024-03-06T08:59:08.67218Z  Error: Failed to publish your Function. Got error: Uncaught ReferenceError: __VUE_PROD_DEVTOOLS__ is not defined
  at functionsWorker-0.21662718510522527.js:2657:29
  at functionsWorker-0.21662718510522527.js:41:39
  at functionsWorker-0.21662718510522527.js:3065:3
  at functionsWorker-0.21662718510522527.js:41:39
  at functionsWorker-0.21662718510522527.js:3256:3
  at functionsWorker-0.21662718510522527.js:41:39
  at functionsWorker-0.21662718510522527.js:3529:3
  at functionsWorker-0.21662718510522527.js:41:39
  at functionsWorker-0.21662718510522527.js:6059:1

Any help or hints much appreciated.

What's the expected result?

Expected result would be a successful build/deploy.

Link to Minimal Reproducible Example

...

Participation

alexanderniebuhr commented 4 months ago

That error looks like an environment variable issue, so you might need to add the missing env var __VUE_PROD_DEVTOOLS__ in Cloudflare dashboard: https://developers.cloudflare.com/pages/configuration/build-configuration/#environment-variables.

However I'm a bit confused why it want's that variable, are you using that variable?

npenner commented 4 months ago

I actually already tried setting it via CF env variables without any success. Same error at the same point. I am not using the var in my project. While trying to find a solution i stumbled across this info: https://vuejs.org/api/compile-time-flags.html Seems like a relevant piece of information since i have a vue component in my project. But then again here it states that vite provides default values for these flags: https://vuejs.org/api/compile-time-flags.html#vite

So no real progress there ...

alexanderniebuhr commented 4 months ago

Please share a minimal reproduction or open a support thread on Discord

bluwy commented 4 months ago

Related: https://github.com/withastro/astro/issues/10339

npenner commented 4 months ago

@alexanderniebuhr I will try to setup a minimal reproduction asap. Might take a day though due to other projects. Thanks so far.

npenner commented 4 months ago

@alexanderniebuhr I've setup basically a copy of the project at codesandbox. The project is a frontend to a headless wordpress. Since it is a client project i had to clear some info and cannot actually connect the source CMS. So the fetch fails due to the missing urls / env vars.

But you should get the idea and scope of the project and maybe this helps. https://codesandbox.io/p/devbox/astro-frontend-36g7px

Let me know if there is anything else i can provide. Thanks again for looking into this.

p.s. please keep in mind this is work in progress and i am pretty new to astro :)

alexanderniebuhr commented 4 months ago

I hope you're doing well! I truly appreciate you taking the time to share your project with us. It's clear you've put a lot of effort into it, and that really shines through. 😊

While the project you shared is comprehensive, we find that starting with a more minimal example often helps us get to the root of the problem more efficiently. Would you be able to set up a minimal version of your project using an empty Astro project from https://astro.new/? This way, you can include just the essential elements needed to replicate the issue—likely just the Cloudflare adapter, the Vue Integration, and one Vue component.

Creating this minimal reproducible example helps us immensely as it allows us maintainers to focus directly on the issue without the complexity of the full project. I understand it might feel like an extra step, but it genuinely makes a huge difference in how quickly and effectively we can offer support and solutions.

If you need any guidance on how to set this up or if you have any questions, please don't hesitate to reach out in Discord. We're here to help, and we want to make sure your experience is as smooth and enjoyable as possible.

npenner commented 4 months ago

Sure. I guess this would be this. https://stackblitz.com/edit/github-sn3uou

alexanderniebuhr commented 4 months ago

That's an interesting issue.. I can reproduce it now, thanks for submitting!

npenner commented 4 months ago

@alexanderniebuhr fyi, maybe it helps i just deployed the completely same app to vercel successfully. just the basic config:

import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import vue from '@astrojs/vue';
import vercelServerless from '@astrojs/vercel/serverless';

// https://astro.build/config
export default defineConfig({
  output: 'server',
  adapter: vercelServerless(),
  integrations: [tailwind(), vue()]
});

i needed an alternative because of the projects timing.

alexanderniebuhr commented 4 months ago

Thank you. I'm sorry for the delay, but this would be fixed with v10 only and I don't have an ETA on that

npenner commented 4 months ago

No worries. I am using free software here, so all i can be is grateful anyway!