stripe-samples / stripe-node-cloudflare-worker-template

Use stripe-node in a Cloudflare Worker.
MIT License
77 stars 16 forks source link

Broken from the get go..? #2

Closed spencercap closed 1 year ago

spencercap commented 2 years ago

Bug report

Hi, I'm excited that Stripe is now supported natively in Cloudflare's runtime but after using this repo as a template as indicated in the readme, I cannot run the build script. webpack fails with the message below and then I cannot use wrangler publish or wrangler dev. Please let me know what changes are needed - thanks!

> webpack --progress

assets by status 859 KiB [cached] 1 asset
runtime modules 344 bytes 2 modules
modules by path ./node_modules/ 1.65 MiB
  javascript modules 1.63 MiB 330 modules
  json modules 20 KiB
    modules by path ./node_modules/browserify-sign/ 5.86 KiB 5 modules
    modules by path ./node_modules/public-encrypt/ 2.52 KiB
      ./node_modules/public-encrypt/node_modules/parse-asn1/aesid.json 487 bytes [built] [code generated]
      ./node_modules/public-encrypt/node_modules/browserify-aes/modes/list.json 2.05 KiB [built] [code generated]
optional modules 165 bytes [optional] 11 modules
./src/index.js 1020 bytes [built] [code generated]
http (ignored) 15 bytes [built] [code generated]
https (ignored) 15 bytes [built] [code generated]
./util.inspect (ignored) 15 bytes [built] [code generated]
util (ignored) 15 bytes [built] [code generated]
util (ignored) 15 bytes [built] [code generated]

ERROR in ./node_modules/browserify-cipher/node_modules/cipher-base/index.js 3:20-59
Module not found: Error: Can't resolve 'string_decoder' in '/Users/spencer/Downloads/stripey-bricks/node_modules/browserify-cipher/node_modules/cipher-base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "string_decoder": require.resolve("string_decoder/") }'
        - install 'string_decoder'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "string_decoder": false }
 @ ./node_modules/browserify-cipher/node_modules/browserify-des/index.js 1:17-39
 @ ./node_modules/browserify-cipher/browser.js 1:10-35
 @ ./node_modules/crypto-browserify/index.js 18:10-38
 @ ./node_modules/stripe/lib/utils.js 5:15-32
 @ ./node_modules/stripe/lib/stripe.js 14:14-32
 @ ./src/index.js 1:15-32

ERROR in ./node_modules/browserify-sign/node_modules/cipher-base/index.js 3:20-59
Module not found: Error: Can't resolve 'string_decoder' in '/Users/spencer/Downloads/stripey-bricks/node_modules/browserify-sign/node_modules/cipher-base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "string_decoder": require.resolve("string_decoder/") }'
        - install 'string_decoder'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "string_decoder": false }
 @ ./node_modules/browserify-sign/node_modules/browserify-aes/encrypter.js 5:16-38
 @ ./node_modules/browserify-sign/node_modules/browserify-aes/browser.js 1:14-36
 @ ./node_modules/browserify-sign/node_modules/parse-asn1/index.js 4:14-39
 @ ./node_modules/browserify-sign/browser/verify.js 5:16-37
 @ ./node_modules/browserify-sign/browser/index.js 6:13-32
 @ ./node_modules/crypto-browserify/index.js 39:11-37
 @ ./node_modules/stripe/lib/utils.js 5:15-32
 @ ./node_modules/stripe/lib/stripe.js 14:14-32
 @ ./src/index.js 1:15-32

ERROR in ./node_modules/create-hash/node_modules/cipher-base/index.js 3:20-59
Module not found: Error: Can't resolve 'string_decoder' in '/Users/spencer/Downloads/stripey-bricks/node_modules/create-hash/node_modules/cipher-base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "string_decoder": require.resolve("string_decoder/") }'
        - install 'string_decoder'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "string_decoder": false }
 @ ./node_modules/create-hash/browser.js 6:11-33
 @ ./node_modules/crypto-browserify/index.js 4:21-58
 @ ./node_modules/stripe/lib/utils.js 5:15-32
 @ ./node_modules/stripe/lib/stripe.js 14:14-32
 @ ./src/index.js 1:15-32

ERROR in ./node_modules/create-hmac/node_modules/cipher-base/index.js 3:20-59
Module not found: Error: Can't resolve 'string_decoder' in '/Users/spencer/Downloads/stripey-bricks/node_modules/create-hmac/node_modules/cipher-base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "string_decoder": require.resolve("string_decoder/") }'
        - install 'string_decoder'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "string_decoder": false }
 @ ./node_modules/create-hmac/browser.js 4:11-33
 @ ./node_modules/crypto-browserify/index.js 5:21-58
 @ ./node_modules/stripe/lib/utils.js 5:15-32
 @ ./node_modules/stripe/lib/stripe.js 14:14-32
 @ ./src/index.js 1:15-32

ERROR in ./node_modules/public-encrypt/node_modules/cipher-base/index.js 3:20-59
Module not found: Error: Can't resolve 'string_decoder' in '/Users/spencer/Downloads/stripey-bricks/node_modules/public-encrypt/node_modules/cipher-base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "string_decoder": require.resolve("string_decoder/") }'
        - install 'string_decoder'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "string_decoder": false }
 @ ./node_modules/public-encrypt/node_modules/browserify-aes/encrypter.js 5:16-38
 @ ./node_modules/public-encrypt/node_modules/browserify-aes/browser.js 1:14-36
 @ ./node_modules/public-encrypt/node_modules/parse-asn1/index.js 4:14-39
 @ ./node_modules/public-encrypt/publicEncrypt.js 1:16-37
 @ ./node_modules/public-encrypt/browser.js 1:0-50
 @ ./node_modules/crypto-browserify/index.js 48:20-45
 @ ./node_modules/stripe/lib/utils.js 5:15-32
 @ ./node_modules/stripe/lib/stripe.js 14:14-32
 @ ./src/index.js 1:15-32

5 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.65.0 compiled with 5 errors in 8017 ms
npm ERR! code ELIFECYCLE
npm ERR! errno 1

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. use this repo as a template: wrangler generate projectname https://github.com/stripe-samples/stripe-node-cloudflare-worker-template
  2. install in directory: npm i
  3. npm run build
  4. See error

Expected behavior

As readme says.

System information

mrbm commented 2 years ago

i haven't got this working, but noticing you are running npm run build, but this is a workers project and you must use wrangler publish right? I'm still new with it.

spencercap commented 2 years ago

i haven't got this working, but noticing you are running npm run build, but this is a workers project and you must use wrangler publish right? I'm still new with it.

well wrangler uses webpack to build under the hook. wrangler also serves workers locally + deploys them etc.


in other news, i upgraded to node 15 and this template repo works fine 👍

mrbm commented 2 years ago

I'm still working on this...haven't finished going through things (i'm merging things in with another project)...but just got things to compile. Make sure you have your account settings are set up with cloudflare, and also make sure you install: npm install webpack-cli

that was my issue that was halting my compile. Also I am using a much newer version of mac os and node v16.0, are you sure node 14 is compatible with wrangler

kpetrillo commented 1 year ago

Is this being supported at all? This isn't working with Nuxt.

anniel-stripe commented 1 year ago

Hi everyone, apologies for the wait here. We've recently updated stripe-node so that polyfills are no longer needed for Cloudflare worker compatibility starting with v11.10.0. We've also updated this sample to reflect this and to use Wrangler 2 - please refer to the latest README for usage instructions.

If you are still encountering issues with this sample, please don't hesitate to open a new issue!