ricmoo / aes-js

A pure JavaScript implementation of the AES block cipher and all common modes of operation for node.js or web browsers.
MIT License
1.45k stars 272 forks source link

export an es module #105

Open wighawag opened 3 years ago

wighawag commented 3 years ago

aes-js is currently causing issue for es-module based system like https://vitejs.dev/

I am getting this error :

TypeError: Cannot read property 'aesjs' of undefined
    at /@fs/C:/dev/wighawag/jolly-roger/node_modules/.pnpm/aes-js@3.0.0/node_modules/aes-js/index.js:790:18
    at /@fs/C:/dev/wighawag/jolly-roger/node_modules/.pnpm/aes-js@3.0.0/node_modules/aes-js/index.js:798:3
    at instantiateModule (C:\dev\wighawag\jolly-roger\node_modules\.pnpm\vite@2.1.5\node_modules\vite\dist\node\chunks\dep-66eb515d.js:69030:166)

which indicate that this line fails root is undefined : https://github.com/ricmoo/aes-js/blob/7c9fad4add4b349dcb89a4e2125f37defaef3bc8/index.js#L795

Note that the error comes when importing @ethersproject/wallet that relies on aes-js

My current workaround is to use my fork of aes-js which expose es-module only via this minimal change : https://github.com/ricmoo/aes-js/compare/master...wighawag:as-es-module

t3db0t commented 3 years ago

I second this. I'm using this in a React project and had to manually redo the exports in order to import it.

ricmoo commented 3 years ago

I third this, as the author of aes-js and ethers. :)

This has been on my backlog for some time and I should be able to get to it this upcoming week. I want to update scrypt-js too.