GithubHelp home page GithubHelp logo

crypto is not defined about aws4fetch HOT 9 OPEN

its-dibo avatar its-dibo commented on August 25, 2024
crypto is not defined

from aws4fetch.

Comments (9)

zdmc23 avatar zdmc23 commented on August 25, 2024 1

@its-dibo , try adding the Vercel Edge Runtime Polyfill (https://edge-runtime.vercel.app/packages/ponyfill) package:

pnpm add @edge-runtime/ponyfill

then to use it:

import { crypto } from '@edge-runtime/ponyfill'

from aws4fetch.

luizzappa avatar luizzappa commented on August 25, 2024 1

In case anyone is having this problem running Nuxt locally, you can create a plugin as follows:

export default defineNuxtPlugin(() => {
  const config = useRuntimeConfig();

  if (process.server && config.public.env.toLocaleLowerCase() !== 'prod') {
    const crypto = require('crypto');
    global.crypto = crypto;
  }
})

from aws4fetch.

mhart avatar mhart commented on August 25, 2024

Where are you running this? As the README says, this is "for environments that support fetch and SubtleCrypto"

from aws4fetch.

its-dibo avatar its-dibo commented on August 25, 2024

Where are you running this? As the README says, this is "for environments that support fetch and SubtleCrypto"

in a Nodejs app which supports fetch

from aws4fetch.

mhart avatar mhart commented on August 25, 2024

from aws4fetch.

its-dibo avatar its-dibo commented on August 25, 2024

Which Node.js version? Which OS?

Node v20
OS: ubuntu 22

from aws4fetch.

mhart avatar mhart commented on August 25, 2024

Not sure what's wrong with your env – it's defined for me:

$ node
Welcome to Node.js v20.11.0.
Type ".help" for more information.
> typeof crypto
'object'

from aws4fetch.

sino1641 avatar sino1641 commented on August 25, 2024

HI
I tried adding const crypto = require('crypto'); to the top of the code then it works.
I am day1 on nodejs using fedora with node output:

$ node
Welcome to Node.js v18.18.2.
Type ".help" for more information.
> typeof crypto
'object'

May it wouldbe of help.

from aws4fetch.

its-dibo avatar its-dibo commented on August 25, 2024

I tried adding const crypto = require('crypto');

this wo'nt work here because aws4fetch is an external package and we cannot modify its code base

from aws4fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.