Skip to content

Can't use cf-workers-algolia-search with cf pages functions due to require('crypto') in original algoliasearch #15

@eltorio

Description

@eltorio

Hi Greg,
Thanks for your work.
I'd like to use your algoliasearch wrapper for Cloudflare worker. I use it for replacing algoliasearch in my Cloudflare Pages function (light worker embedded in pages). Since original algoliasearch use XHR wich is not supported by Cloudflare I thought that your work is THE solution.
in my package.json I declared:

"@glenstack/cf-workers-algolia-search": "^1.0.2",

and in my function:

import algoliasearch from "@glenstack/cf-workers-algolia-search";

But Wrangler2 complains about missing crypto module

Compiling worker to "/var/folders/07/873_g9sx2zjdm0qzs62h_nvr0000gn/T/functionsWorker.js"...
✘ [ERROR] Could not resolve "crypto"

    node_modules/@glenstack/cf-workers-algolia-search/node_modules/@algolia/client-search/dist/client-search.cjs.js:8:21:
      8 │ var crypto = require('crypto');~~~~~~~~

  The package "crypto" 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.

1 error(s) and 0 warning(s) when compiling Worker.
Build failed with 1 error:
node_modules/@glenstack/cf-workers-algolia-search/node_modules/@algolia/client-search/dist/client-search.cjs.js:8:21: ERROR: Could not resolve "crypto"

If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.

Cloudflare Worker does not require deprecated crypto 1.0.1 since it provides directly Web Crypto Subtle https://developers.cloudflare.com/workers/runtime-apis/web-crypto/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions