Can't build with Sveltekit for Cloudflare
Closed this issue · 4 comments
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Using jsc8 version 0.16.3
Using Sveltekit version 1.0.0-next.295
Using @sveltejs/adapter-cloudflare-workers version 1.0.0-next.35
Issue Description
No problems running in Sveltekit's dev mode.
But doing a build, which is a pre-requisite for a Wrangler publish I get the following errors:
> Using @sveltejs/adapter-cloudflare-workers
✘ [ERROR] Could not resolve "querystring"
node_modules/jsc8/lib/cjs/connection.js:12:30:
12 │ const querystring_1 = require("querystring");
╵ ~~~~~~~~~~~~~
The package "querystring" 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] Could not resolve "url"
node_modules/jsc8/lib/cjs/util/request.web.js:3:22:
3 │ const url_1 = require("url");
╵ ~~~~~
The package "url" 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] Could not resolve "path"
node_modules/jsc8/lib/cjs/util/joinPath.web.js:3:21:
3 │ var path_1 = require("path");
╵ ~~~~~~
The package "path" 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.
> Build failed with 3 errors:
node_modules/jsc8/lib/cjs/connection.js:12:30: ERROR: Could not resolve "querystring"
node_modules/jsc8/lib/cjs/util/joinPath.web.js:3:21: ERROR: Could not resolve "path"
node_modules/jsc8/lib/cjs/util/request.web.js:3:22: ERROR: Could not resolve "url"
Steps to Reproduce
Create any simple app that uses jsc8.js and run npm run build
or npx svelte-kit build
Current Behavior
Build fails with above mentioned erros
Expected Behavior
Building without errors
@eric-naguras Apologies for the delay. The error is coming from native node modules required by the jsc8 SDK. While it's possible to polyfill these libraries in a browser environment, we highly recommend against doing so. Running the jsc8 library in a browser environment comes with significant risk as your Macrometa credentials would be visible in your source code.
If you're querying data stored in GDN, I'd recommend the two options:
1. Proxy requests to a backend API and query GDN from the server environment. This will ensure that your Macrometa credentials are secure.
2. Use RestQL to query the data you need – you can find out more about RestQL here in our docs.
@nparsons08 Thanks for the reply. I did go for option 2. Seems like an even better way to do things. I have no problems using RestQL.
Awesome! We are here if you need help in the future @eric-naguras. Happy coding!
@nparsons08 So far, I think Macrometa is a great product and a perfect match for serverless. I'm saving up some questions that I will ask later. Even though the documentation is a bit sparse, I don't have much problems using the database.