Open dcaslin opened 3 years ago
Well this is interesting. I had an older project I setup to test all this and I jumped back to it and, good news, it builds, but it then fails to publish to CF.
package.json of building (but not publishing) project:
{
"name": "~TODO~",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"preview": "svelte-kit preview",
"publish": "svelte-kit build && wrangler publish",
"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.12",
"@sveltejs/kit": "next",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-svelte3": "^3.2.0",
"prettier": "~2.2.1",
"prettier-plugin-svelte": "^2.2.0",
"svelte": "^3.38.2",
"svelte-check": "^2.0.0",
"svelte-preprocess": "^4.7.3",
"tslib": "^2.0.0",
"typescript": "^4.0.0",
"postcss": "^8.3.5",
"postcss-load-config": "^3.1.0",
"autoprefixer": "^10.2.6",
"cssnano": "^5.0.6",
"tailwindcss": "^2.2.4"
},
"type": "module",
"dependencies": {
"apexcharts": "^3.27.1",
"faker": "^5.5.3",
"sk-auth": "^0.3.7",
"sveltestrap": "^5.2.1"
}
}
Wrangler publish error:
Error: Something went wrong! Status: 400 Bad Request, Details {
"result": null,
"success": false,
"errors": [
{
"code": 10021,
"message": "Uncaught ReferenceError: require is not defined\n at line 140572 in node_modules/safe-buffer/index.js\n at line 9 in __require\n at line 141103 in node_modules/jws/lib/sign-stream.js\n at line 9 in __require\n at line 141283 in node_modules/jws/index.js\n at line
9 in __require\n at line 141316 in node_modules/jsonwebtoken/decode.js\n at line 9 in __require\n at line 143373 in node_modules/jsonwebtoken/index.js\n at line 9 in __require\n"
}
],
"messages": []
}
Btw, if this means sk-auth + CF workers isn't a good fit yet, that's fair. (And if so, What adapter would you recommend as the most stable choice instead?)
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.
Thanks! Based on your note here and advice in the SvelteKit discord I've moved my little hobby project over to the node adapter. I haven't gotten a chance to deploy yet, but dev wise this plugin is working great, thx for your work!
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?
I'm getting this build error on vercel. (Local environment is working.)
[commonjs--resolver] Failed to resolve entry for package "sk-auth". The package may have incorrect main/module/exports specified in its package.json.
--
16:14:37.092 | [vite-plugin-svelte-kit] Failed to resolve entry for package "sk-auth". The package may have incorrect main/module/exports specified in its package.json.
16:14:37.096 | error during build:
16:14:37.096 | Error: Failed to resolve entry for package "sk-auth". The package may have incorrect main/module/exports specified in its package.json.
16:14:37.096 | at packageEntryFailure (file:///vercel/path0/node_modules/vite/dist/node/chunks/dep-c6273c7a.js:34410:11)
16:14:37.096 | at resolvePackageEntry (file:///vercel/path0/node_modules/vite/dist/node/chunks/dep-c6273c7a.js:34407:5)
16:14:37.096 | at tryNodeResolve (file:///vercel/path0/node_modules/vite/dist/node/chunks/dep-c6273c7a.js:34161:20)
16:14:37.097 | at Object.resolveId (file:///vercel/path0/node_modules/vite/dist/node/chunks/dep-c6273c7a.js:33963:28)
16:14:37.097 | at Object.<anonymous> (file:///vercel/path0/node_modules/vite/dist/node/chunks/dep-c6273c7a.js:43670:19)
16:14:37.097 | at file:///vercel/path0/node_modules/rollup/dist/es/shared/rollup.js:22695:37
16:14:37.123 | error Command failed with exit code 1.
Is the root cause same as this? here's my svelte.conf.js and vite.conf.js.
// svelte.conf.js
import adapter from '@sveltejs/adapter-auto';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter()
}
};
export default config;
//vite.conf.js
import { sveltekit } from '@sveltejs/kit/vite';
import { resolve } from 'path';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()],
ssr: {noExternal: ['chart.js']},
resolve: {alias: {
$src: resolve('./src'),
$components: resolve('./src/components'),
}}
};
export default config;
I 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
And here's my package.json
Error log below: