jorjik
05/18/2023, 6:58 PMwrangler dev
it setup the server and function are working, the syntax are different for the functions - for workers and for page functions?Skye
05/18/2023, 6:59 PMSkye
05/18/2023, 7:00 PM_worker.js
file in _site and use the same syntax as you're using nowjorjik
05/18/2023, 7:07 PMhanpolo
05/20/2023, 12:09 AMimport { randomBytes } from 'crypto'
in my local pages dev.
My command line is:
npx wrangler pages dev \
--compatibility-flags="nodejs_compat" --experimental-local \
--kv=SOMETHING --kv=TEST --kv=CONFIG \
--do TEST_DO=TestDO@test-do-dev \
--d1=TEST_DB --persist \
-- npm start
However, the build fails with message:
The package "crypto" wasn't found on the file system but is built into node.
Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.
Any ideas what I'm doing wrong?Walshy | Pages
05/20/2023, 12:17 AMhanpolo
05/20/2023, 12:18 AMWalshy | Pages
05/20/2023, 12:20 AMSkye
05/20/2023, 12:20 AMhanpolo
05/20/2023, 12:21 AMhanpolo
05/20/2023, 12:21 AMWalshy | Pages
05/20/2023, 12:25 AMWalshy | Pages
05/20/2023, 12:25 AMWalshy | Pages
05/20/2023, 12:25 AMhanpolo
05/20/2023, 12:26 AMWalshy | Pages
05/20/2023, 12:27 AMhanpolo
05/20/2023, 12:31 AMmodichutiyathaaurhai
05/20/2023, 9:59 AMIsaac McFadyen | YYZ01
05/20/2023, 1:00 PMwrangler pages dev
?Isaac McFadyen | YYZ01
05/20/2023, 1:01 PMIsaac McFadyen | YYZ01
05/20/2023, 1:01 PMwrangler pages dev ./build
or whatever your folder is calledizdi
05/21/2023, 6:32 AMfunctions
to build backend, however I stuck with lack of knowledge on how to enable npm
modules. I see that workers has this capabilities using wrangler cli out of the box, is there any guide/example for functions? Thanks 🗿Skye
05/21/2023, 9:35 AMizdi
05/21/2023, 8:10 PM22:05:01.912 ./workers/src/index.ts:29:47
22:05:01.912 Type error: Cannot find name 'ExecutionContext'.
22:05:01.912
22:05:01.912 27 |
22:05:01.912 28 | export default {
22:05:01.912 > 29 | async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<any> {
22:05:01.912 | ^
22:05:01.913 30 | if (env.router === undefined) {
22:05:01.913 31 | env.router = buildRouter(env);
22:05:01.913 32 | }
In this example it is related to workers, but prior to that I had the same issues with functions
in the root folder of the next.js project.izdi
05/21/2023, 8:26 PMnora
05/21/2023, 8:26 PMnora
05/21/2023, 8:26 PMizdi
05/21/2023, 8:37 PMfunctions/api/inquiry.js
endpoint to use Notion SDK import { Client } from "@notionhq/client"
, so when I added the external package I got now another failed build with this statement
22:30:18.149 Found Functions directory at /functions. Uploading.
22:30:18.882 ✨ Compiled Worker successfully
22:30:18.943 Validating asset output directory
22:30:19.550 Deploying your site to Cloudflare's global network...
22:30:22.711 Uploading... (72/79)
22:30:23.178 Uploading... (74/79)
22:30:23.454 Uploading... (76/79)
22:30:23.846 Uploading... (79/79)
22:30:23.846 ✨ Success! Uploaded 7 files (72 already uploaded) (1.62 sec)
22:30:23.846
22:30:24.343 ✨ Upload complete!
22:30:25.957 Success: Assets published!
22:30:26.821 Error: Failed to publish your Function. Got error: Uncaught ReferenceError: global is not defined
at functionsWorker-0.19086037171855352.js:477:49 in ../node_modules/node-fetch/browser.js
at functionsWorker-0.19086037171855352.js:11:50 in __require
at functionsWorker-0.19086037171855352.js:584:24 in ../node_modules/@notionhq/client/build/src/Client.js
at functionsWorker-0.19086037171855352.js:11:50 in __require
at functionsWorker-0.19086037171855352.js:932:20 in ../node_modules/@notionhq/client/build/src/index.js
at functionsWorker-0.19086037171855352.js:11:50 in __require
at functionsWorker-0.19086037171855352.js:1128:29 in api/inquiry.js
at functionsWorker-0.19086037171855352.js:8:56 in __init
at functionsWorker-0.19086037171855352.js:1136:5 in ../../../../tmp/functionsRoutes-0.015377362220493573.mjs
at functionsWorker-0.19086037171855352.js:8:56 in __init
Are there some specifics I'm missing on how to import packages in functions or setup with next.js?