sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.44k stars 1.89k forks source link

Build fail on `@sveltejs/adapter-cloudflare` #9983

Closed GoodGoodJM closed 1 year ago

GoodGoodJM commented 1 year ago

Describe the bug

Our project hosted on vercel. We decide move to cloudflare.

We checked docs(https://kit.svelte.dev/docs/adapter-cloudflare, https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site/) and install adapter and try to build("build": "CF_PAGES=1 vite build")

But build occur error and logs(see attached logs).

In my opinion, the compiler can't compile the ts.

Reproduction

install @sveltejs/adapter-cloudflare and build("build": "CF_PAGES=1 vite build")

Logs

npm run build

> front@0.0.1 build
> CF_PAGES=1 vite build

vite v4.0.4 building SSR bundle for production...
✓ 1 modules transformed.
[vite-plugin-svelte] /src/routes/+layout.svelte:7:13 Unexpected token
file: /Users/goodgoodman/work/service/front/src/routes/+layout.svelte:7:13
  5 |    import '../app.css';
  6 |    import { userContext } from '$lib/context/user';
  7 |    import type { LayoutData } from './$types';
                     ^
  8 |    import { browser } from '$app/environment';
  9 |    import { goto } from '$app/navigation';
error during build:
ParseError: Unexpected token
    at error (file:///Users/goodgoodman/work/servicefront/node_modules/svelte/compiler.mjs:13140:19)
    at Parser$1.error (file:///Users/goodgoodman/work/service/front/node_modules/svelte/compiler.mjs:13218:9)
    at Parser$1.acorn_error (file:///Users/goodgoodman/work/service/front/node_modules/svelte/compiler.mjs:13212:14)
    at Object.read_script [as read] (file:///Users/goodgoodman/work/service/front/node_modules/svelte/compiler.mjs:8999:16)
    at tag (file:///Users/goodgoodman/work/service/front/node_modules/svelte/compiler.mjs:12164:33)
 ...
 ...

System Info

npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: macOS 12.5
    CPU: (8) arm64 Apple M1 Pro
    Memory: 80.52 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.7.0 - ~/.asdf/installs/nodejs/18.7.0/bin/node
    npm: 8.15.0 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 113.0.5672.126
    Firefox: 112.0.2
    Safari: 15.6
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.2
    @sveltejs/adapter-cloudflare: ^2.2.4 => 2.2.4
    @sveltejs/kit: ^1.16.2 => 1.18.0
    svelte: ^3.58.0 => 3.58.0
    vite: ^4.0.0 => 4.0.4

Severity

blocking all usage of SvelteKit

Additional Information

No response

GoodGoodJM commented 1 year ago

I attached relevant part of code to logs.

// ./src/routes/+layout.svelte
<script lang="ts">
    import { getAuth, onIdTokenChanged } from 'firebase/auth';
    import { onMount } from 'svelte';
    import '$lib/firebase/client';
    import '../app.css';
    import { userContext } from '$lib/context/user';
    import type { LayoutData } from './$types';
/** ... */
gtm-nayan commented 1 year ago

I doubt solely switching adapters would've changed how your svelte file is getting parsed. You might've messed something up in the migration, eg: you pasted in the config from docs and accidentally removed the preprocessor.

Otherwise you need to provide a minimal reproduction for us to know what the problem is as you were instructed by the issue template.

Please provide a proper reproduction for the issue as instructed by the issue template:

A link to a repository, or a fork of https://node.new/sveltekit, that reproduces the issue. Reproductions must be short, self-contained and correct and must not contain files or code that aren't relevant to the issue — please do NOT just paste a link to your project. Explaining how to reproduce is generally not enough. It pushes the burden of creating a reproduction project onto a small set of volunteer maintainers and isn't scalable. If no reproduction is provided, the issue will be closed.

GoodGoodJM commented 1 year ago

@gtm-nayan Yes, you are right. I accidentally deleted the preprocessor, and since I restored it, it goes a little further.

> Using @sveltejs/adapter-cloudflare
✘ [ERROR] Could not resolve "@firebase/database-compat/standalone"

    node_modules/firebase-admin/lib/app/firebase-namespace.js:106:41:
      106 │         return Object.assign(fn, require('@firebase/database-compat/standalone'));
          ╵                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The path "./standalone" is not currently exported by package "@firebase/database-compat":

    node_modules/@firebase/database-compat/package.json:16:13:
      16 │   "exports": {
         ╵              ^

  None of the conditions provided ("types", "node") match any of the currently active conditions
  ("browser", "default", "require", "worker"):

    node_modules/@firebase/database-compat/package.json:27:20:
      27 │     "./standalone": {
         ╵                     ^

  Consider enabling the "types" condition if this package expects it to be enabled. You can use
  "conditions: ['types']" to do that:

    node_modules/@firebase/database-compat/package.json:28:6:
      28 │       "types": "./dist/database-compat/src/index.standalone.d.ts",
         ╵       ~~~~~~~

  You can mark the path "@firebase/database-compat/standalone" as external to exclude it from the
  bundle, which will remove this error. You can also surround this "require" call with a try/catch
  block to handle this failure at run-time instead of bundle-time.

✘ [ERROR] Could not resolve "fs"
...
...
...

  The package "fs" 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 94 errors:
node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:3:31: ERROR: Could not resolve "stream"
node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:3:29: ERROR: Could not resolve "events"
node_modules/@fastify/busboy/deps/dicer/lib/PartStream.js:4:31: ERROR: Could not resolve "stream"
node_modules/@fastify/busboy/deps/streamsearch/sbmh.js:29:29: ERROR: Could not resolve "events"
node_modules/@fastify/busboy/lib/main.js:3:31: ERROR: Could not resolve "stream"
dummdidumm commented 1 year ago

Again, we need a minimum reproducible to look into this. Creating the minimum reproducible might also reveal that the issue is unrelated to SvelteKit and fix it directly on your end.

GoodGoodJM commented 1 year ago

https://github.com/firebase/firebase-admin-node/issues/2069

I think it should be solved in firebase-admin, I realized it during the reproduction. Thank you to those who have responded to this issue.