Adyen / adyen-cse-web

[DEPRECATED] Client-side encryption on JavaScript
MIT License
15 stars 39 forks source link

Module not found: Error: Can't resolve 'crypto' #81

Closed Ruud-cb closed 5 years ago

Ruud-cb commented 5 years ago

Hi,

I am getting the following Warning when building my angular app for production:

WARNING in ./node_modules/adyen-cse-js/js/adyen.encrypt.nodom.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Ruud\source\repos\Babywatcher\Babywatcher.Web.Shop\ClientApp\node_modules\adyen-cse-js\js'

Although it is a warning, it does produce an error in production (my CI for example doesn't like it). According to your documentation you suggest importing with require, but I cannot do this because of the following error when I do so:

ERROR in src/app/payment/method/method.component.ts(16,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

So it basically enforces me to write it like this:

import * as adyenEncrypt from 'adyen-cse-js';

Could you please update your lib? Googling on the issue gives quite a few of potential fixes.

mastermatt commented 5 years ago

I'm not with Adyen, but note that adyen-cse-js is not an official publication of this lib. The official NPM pkg is https://www.npmjs.com/package/adyen-cse-web, but it states this lib is deprecated.

Ruud-cb commented 5 years ago

Yeah well this npm package does not mention deprecation. And secure fields does not work well with SPAs.

I could workaround this issue by including the .js file in my project and then do it like this in my component:

var adyenEncrypt = (<any>window).adyen.encrypt;

Adyen team: I hope you can manage to upgrade this package again so that it is perfectly compatible with the most common front-end framworks. If you think secure fields works better then perhaps it is useful to write some more dev-tutorials.