Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 7.0.0 not compatible with Azure Functions/AWS Lambda/Google Cloud Functions #378

Closed
ctavan opened this issue Feb 24, 2020 · 9 comments · Fixed by #380
Closed

Version 7.0.0 not compatible with Azure Functions/AWS Lambda/Google Cloud Functions #378

ctavan opened this issue Feb 24, 2020 · 9 comments · Fixed by #380

Comments

@ctavan
Copy link
Member

ctavan commented Feb 24, 2020

References:

@evdama
Copy link

evdama commented Feb 25, 2020

It's not just Azure. AWS lambda as well as google cloud functions, and therefore firebase cloud functions, have the same issue

Error: uuid: This browser does not seem to support crypto.getRandomValues(). If you need to support this browser, please provide a custom random number generator through options.rng.

@ctavan
Copy link
Member Author

ctavan commented Feb 25, 2020

@evdama @jvpelt @VandalPaulius @ZebraFlesh could you please share more details about your Azure Functions/AWS Lambda/Google Cloud Functions setup with steps to reproduce the error?

My suspicion is that you are bundling code in a way that is designed to run in a browser environment, not in Node.js

So are any bundlers like webpack or rollup involved in your process?

I created a minimalistic PoC that shows that under normal circumstances using uuid in Cloud Functions works just well: https://github.com/ctavan/uuid-cloud-functions-poc

@ctavan ctavan changed the title Version 7.0.0 not compatible with Azure Functions Version 7.0.0 not compatible with Azure Functions/AWS Lambda/Google Cloud Functions Feb 25, 2020
@evdama
Copy link

evdama commented Feb 25, 2020

yes, I use rollup to bundle uuid, then use it like this in my server.js within express middleware:

import { v4 as uuidv4 } from 'uuid'

const setNonceMiddleware = ( request, response, next ) => {
  try {
    response.locals.nonce = uuidv4()
    next()
  } catch ( error ) {
    console.error ( 'error from setNonceMiddleware: ', error )
  }
}

TrySound added a commit to TrySound/uuid that referenced this issue Feb 25, 2020
Probably will fix uuidjs#378

Currently main field is used for node and module for browser build. This
is not entierly correct. Webpack can be used to build node apps. Though
module is always preferred over main. For browser versions there is a
special field.

In this diff I added esm support for both node and browser.
rollup-plugin-node-resolve look at browser field as well and prefer it
to bundle umd.
TrySound added a commit to TrySound/uuid that referenced this issue Feb 25, 2020
Probably will fix uuidjs#378

Currently main field is used for node and module for browser build. This
is not entierly correct. Webpack can be used to build node apps. Though
module is always preferred over main. For browser versions there is a
special field.

In this diff I added esm support for both node and browser.
rollup-plugin-node-resolve look at browser field as well and prefer it
to bundle umd.
TrySound added a commit to TrySound/uuid that referenced this issue Feb 25, 2020
Probably will fix uuidjs#378

Currently main field is used for node and module for browser build. This
is not entierly correct. Webpack can be used to build node apps. Though
module is always preferred over main. For browser versions there is a
special field.

In this diff I added esm support for both node and browser.
rollup-plugin-node-resolve look at browser field as well and prefer it
to bundle umd.

https://webpack.js.org/configuration/resolve/#resolvemainfields
https://github.com/rollup/plugins/tree/master/packages/node-resolve#browser
https://github.com/defunctzombie/package-browser-field-spec
@ZebraFlesh
Copy link

ZebraFlesh commented Feb 25, 2020

@ctavan Here's a minimal repo with what I'm doing. master branch is set to [email protected]; upgrade to [email protected] to see failure. https://github.com/ZebraFlesh/uuid-serverless-poc

edit: I'm using webpack + serverless + serverless-offline

@ctavan
Copy link
Member Author

ctavan commented Feb 25, 2020

Thank you @ZebraFlesh. I think a fix is near: #380

ctavan pushed a commit that referenced this issue Feb 25, 2020
Probably will fix #378

Currently main field is used for node and module for browser build. This
is not entierly correct. Webpack can be used to build node apps. Though
module is always preferred over main. For browser versions there is a
special field.

In this diff I added esm support for both node and browser.
rollup-plugin-node-resolve look at browser field as well and prefer it
to bundle umd.

https://webpack.js.org/configuration/resolve/#resolvemainfields
https://github.com/rollup/plugins/tree/master/packages/node-resolve#browser
https://github.com/defunctzombie/package-browser-field-spec
TrySound added a commit to TrySound/uuid that referenced this issue Feb 25, 2020
Probably will fix uuidjs#378

Currently main field is used for node and module for browser build. This
is not entierly correct. Webpack can be used to build node apps. Though
module is always preferred over main. For browser versions there is a
special field.

In this diff I added esm support for both node and browser.
rollup-plugin-node-resolve look at browser field as well and prefer it
to bundle umd.

https://webpack.js.org/configuration/resolve/#resolvemainfields
https://github.com/rollup/plugins/tree/master/packages/node-resolve#browser
https://github.com/defunctzombie/package-browser-field-spec
TrySound added a commit to TrySound/uuid that referenced this issue Feb 25, 2020
Probably will fix uuidjs#378

Currently main field is used for node and module for browser build. This
is not entierly correct. Webpack can be used to build node apps. Though
module is always preferred over main. For browser versions there is a
special field.

In this diff I added esm support for both node and browser.
rollup-plugin-node-resolve look at browser field as well and prefer it
to bundle umd.

https://webpack.js.org/configuration/resolve/#resolvemainfields
https://github.com/rollup/plugins/tree/master/packages/node-resolve#browser
https://github.com/defunctzombie/package-browser-field-spec
@VandalPaulius
Copy link

So are any bundlers like webpack or rollup involved in your process?

I created a minimalistic PoC that shows that under normal circumstances using uuid in Cloud Functions works just well: https://github.com/ctavan/uuid-cloud-functions-poc

Yes, in my case I was using Webpack to bundle everything, but the target was set to node. Hopefully #380 will fix it

ctavan pushed a commit that referenced this issue Feb 25, 2020
Fixes #378

Currently main field is used for node and module for browser build. This
is not entierly correct. Webpack can be used to build node apps. Though
module is always preferred over main. For browser versions there is a
special field.

In this diff I added esm support for both node and browser.
rollup-plugin-node-resolve look at browser field as well and prefer it
to bundle umd.

https://webpack.js.org/configuration/resolve/#resolvemainfields
https://github.com/rollup/plugins/tree/master/packages/node-resolve#browser
https://github.com/defunctzombie/package-browser-field-spec
@ctavan
Copy link
Member Author

ctavan commented Feb 25, 2020

I have just released [email protected] which should fix this issue. If the problem remains for anyone please feel free to open a new issue.

And thanks @TrySound for the great work! 🎉

@evdama
Copy link

evdama commented Feb 26, 2020

Thanks much, working again for firebase cloud functions with node express middleware (code see above).

@ZebraFlesh
Copy link

Thanks so much for the quick turn around! Confirmed on my end that my PoC is fixed with 7.0.1 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants