Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[adapter-cloudflare-workers] "Unexpected character '#'" error when running "wrangler publish" #1220

Closed
danawoodman opened this issue Apr 26, 2021 · 1 comment · Fixed by #1287

Comments

@danawoodman
Copy link
Contributor

Describe the bug
Using the CloudFlare Worker adapter with the latest Kit (1.0.0-next.89) and attempting to publish is causing an Unexpected character '#' error:

wrangler publish

up to date, audited 1 package in 137ms

found 0 vulnerabilities
👀  ./workers-site/index.js 3328:2
Module parse failed: Unexpected character '#' (3328:2)
You may need an appropriate loader to handle this file type.
| }
| var ReadOnlyFormData = class {
>   #map;
|   constructor(map) {
|     this.#map = map;

My wrangler.toml:

name = "kit-workers"
type = 'webpack'
account_id = '...'
route = ''
zone_id = ''
usage_model = ''
workers_dev = true
target_type = "webpack"
site = {bucket = "./build", entry-point = "workers-site"}

Logs

To Reproduce

npm init svelte@latest kit-workers
cd kit-workers
npm i -D @sveltejs/adapter-cloudflare-workers@next
# ... add adapter to svelte.config.cjs
wrangler init --site kit-workers
# ... add content to match above (e.g. add account_id and update bucket path)
npm run build
wrangler publish
# error occurs

Expected behavior
It to deploy to CF worker sites :)

Stacktraces
See top

Information about your SvelteKit Installation:

Diagnostics
  • The output of npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers:
  System:
    OS: macOS 11.2
    CPU: (8) arm64 Apple M1
    Memory: 217.56 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.12.0 - ~/.nvm/versions/node/v15.12.0/bin/node
    npm: 7.6.3 - ~/.nvm/versions/node/v15.12.0/bin/npm
  Browsers:
    Brave Browser: 89.1.22.71
    Chrome: 90.0.4430.85
    Safari: 14.0.3
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.89 
    svelte: ^3.29.0 => 3.37.0 
    vite: ^2.1.0 => 2.2.3 
  • Your browser: Brave (not relevant)

  • Your adapter: Cloudflare Workers

Severity
Blocking my usage of CF Workers with Kit but I'm just poking around, so not critical, more of an FYI

Additional context
Not that I can think of!

@CedricDumont
Copy link

a workarround untill fixed (or the fix) is to replace the code in node_modules/@sveltejs/adapter-cloudflare-workers/index.js the esbuild part (esbuild.build{....) with:

await esbuild.build({
				entryPoints: ['.svelte/cloudflare-workers/entry.js'],
				outfile: `${entrypoint}/index.js`,
				bundle: true,
				target: 'es2020',
				platform: 'node' // TODO would be great if we could generate ESM and use type = "javascript"
			});

(set the target to target: 'es2020') as #map is the translation to a private property and not supported by cloudflare at the moment...
I tested and it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants