Cloudflare Worker adapter builds fail with sk-auth
See original GitHub issueI have a simple sveltekit app that works with sk-auth locally, and works with the node adapter build, but fails with the logs below when I try to use the Cloudflare worker adapter. I’ve tried playing around w/ the Vite excludes settings but haven’t had any luck yet.
Here’s my svelite.config.js
import preprocess from 'svelte-preprocess';
import cloudflare from '@sveltejs/adapter-cloudflare-workers';
// import node from '@sveltejs/adapter-node';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [preprocess({
"postcss": true
})],
kit: {
adapter: cloudflare(),
// adapter: node(),
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte'
}
};
export default config;
// Workaround until SvelteKit uses Vite 2.3.8 (and it's confirmed to fix the Tailwind JIT problem)
const mode = process.env.NODE_ENV;
const dev = mode === "development";
process.env.TAILWIND_MODE = dev ? "watch" : "build";
And here’s my package.json
{
"name": "~TODO~",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"preview": "svelte-kit preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --write --plugin-search-dir=. ."
},
"devDependencies": {
"@sveltejs/adapter-cloudflare-workers": "^1.0.0-next.16",
"@sveltejs/adapter-node": "^1.0.0-next.34",
"@sveltejs/adapter-static": "^1.0.0-next.13",
"@sveltejs/kit": "^1.0.0-next.131",
"@tailwindcss/custom-forms": "^0.2.1",
"@typescript-eslint/eslint-plugin": "^4.28.3",
"@typescript-eslint/parser": "^4.28.3",
"autoprefixer": "^10.3.1",
"cssnano": "^5.0.6",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-svelte3": "^3.2.0",
"postcss": "^8.3.5",
"postcss-load-config": "^3.1.0",
"prettier": "~2.2.1",
"prettier-plugin-svelte": "^2.2.0",
"svelte": "^3.34.0",
"svelte-check": "^2.2.3",
"svelte-preprocess": "^4.7.4",
"tailwindcss": "^2.2.4",
"tslib": "^2.0.0",
"typescript": "^4.3.5"
},
"type": "module",
"dependencies": {
"@tailwindcss/forms": "^0.3.3",
"@tailwindcss/typography": "^0.4.1",
"faker": "^5.5.3",
"sk-auth": "^0.3.7"
}
}
Error log below:
> Using @sveltejs/adapter-cloudflare-workers
> node_modules/jws/lib/verify-stream.js:5:21: error: Could not resolve "stream" (use "platform: 'node'" when building for node)
5 │ var Stream = require('stream');
╵ ~~~~~~~~
> node_modules/jws/lib/verify-stream.js:7:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
7 │ var util = require('util');
╵ ~~~~~~
> node_modules/jws/lib/sign-stream.js:5:21: error: Could not resolve "stream" (use "platform: 'node'" when building for node)
5 │ var Stream = require('stream');
╵ ~~~~~~~~
> node_modules/jws/lib/tostring.js:2:21: error: Could not resolve "buffer" (use "platform: 'node'" when building for node)
2 │ var Buffer = require('buffer').Buffer;
╵ ~~~~~~~~
> node_modules/safe-buffer/index.js:3:21: error: Could not resolve "buffer" (use "platform: 'node'" when building for node)
3 │ var buffer = require('buffer')
╵ ~~~~~~~~
> node_modules/jws/lib/data-stream.js:3:21: error: Could not resolve "stream" (use "platform: 'node'" when building for node)
3 │ var Stream = require('stream');
╵ ~~~~~~~~
> node_modules/jws/lib/sign-stream.js:7:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
7 │ var util = require('util');
╵ ~~~~~~
> node_modules/jwa/index.js:3:21: error: Could not resolve "crypto" (use "platform: 'node'" when building for node)
3 │ var crypto = require('crypto');
╵ ~~~~~~~~
> node_modules/jws/lib/data-stream.js:4:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
4 │ var util = require('util');
╵ ~~~~~~
> node_modules/jwa/index.js:5:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
5 │ var util = require('util');
╵ ~~~~~~
> node_modules/buffer-equal-constant-time/index.js:3:21: error: Could not resolve "buffer" (use "platform: 'node'" when building for node)
3 │ var Buffer = require('buffer').Buffer; // browserify
╵ ~~~~~~~~
> Build failed with 11 errors:
node_modules/buffer-equal-constant-time/index.js:3:21: error: Could not resolve "buffer" (use "platform: 'node'" when building for node)
node_modules/jwa/index.js:3:21: error: Could not resolve "crypto" (use "platform: 'node'" when building for node)
node_modules/jwa/index.js:5:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
node_modules/jws/lib/data-stream.js:3:21: error: Could not resolve "stream" (use "platform: 'node'" when building for node)
node_modules/jws/lib/data-stream.js:4:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
...
Error: Build failed with 11 errors:
node_modules/buffer-equal-constant-time/index.js:3:21: error: Could not resolve "buffer" (use "platform: 'node'" when building for node)
node_modules/jwa/index.js:3:21: error: Could not resolve "crypto" (use "platform: 'node'" when building for node)
node_modules/jwa/index.js:5:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
node_modules/jws/lib/data-stream.js:3:21: error: Could not resolve "stream" (use "platform: 'node'" when building for node)
node_modules/jws/lib/data-stream.js:4:19: error: Could not resolve "util" (use "platform: 'node'" when building for node)
...
at failureErrorWithLog (/Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:1449:15)
at /Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:1131:28
at runOnEndCallbacks (/Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:1049:65)
at buildResponseToResult (/Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:1129:7)
at /Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:1236:14
at /Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:609:9
at handleIncomingPacket (/Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:706:9)
at Socket.readFromStdout (/Users/dcaslin/projects/531-calc-2/node_modules/esbuild/lib/main.js:576:7)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:467:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ~TODO~@0.0.1 build: `svelte-kit build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ~TODO~@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Deploy a Svelte site · Cloudflare Pages docs
This will cause the build to fail. Since the environment variables are not ... To add the SvelteKit Cloudflare adapter to your application:....
Read more >@sveltejs/adapter-cloudflare-workers - npm
SvelteKit adapter that creates a Cloudflare Workers site using a function for dynamic server rendering.. Latest version: 1.0.0, ...
Read more >sveltejs/adapter-cloudflare. I get many error while run `npm ...
I'm Using @sveltejs/adapter-cloudflare to deploy my project to Cloudflare Pages. I'm tried to use this package for a simple sveletKit app.
Read more >Deploy your Astro Site to Cloudflare Pages
You can build an Astro SSR site for deployment to Cloudflare Pages using the @astrojs/cloudflare adapter. Follow the steps below to set up...
Read more >The sk-auth from Dan6erbond - Giter VIP
authentication library for use with sveltekit featuring built-in oauth providers and zero restriction ... Cloudflare Worker adapter builds fail with sk-auth.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This seems to be due to a single package -
jsonwebtoken
. Is my observation correct?If so, can it not be replaced with
jose
, which explicitly supports cloudflare workers along with a bunch of other runtimes?Hey there! Thanks for opening this issue!
That’s interesting. I’m not really well versed in CF Workers and how they work, but it seems they’re a serverless platform so the way entrypoints work might be different from having a constantly running Node app, and assets might get optimized differently by Vite, which would explain why it’s complaining about
require()
.The goal is for SKAuth to work on all deploy targets, except in SPA mode or static builds of course, and I can imagine this being an issue for Vercel, Netlify, etc, too, so I’ll be looking into it once I get a chance! First I’ll have to figure out how to isolate and reproduce the issue, though.
Given that, I think there is a chance, that at the moment only the Node adapter will work properly. I’ll look into whether this is an issue with certain dependencies, and if we can get away with switching them out for alternatives, or if a more robust solution is needed.