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

require crypto-js.js commonJS runing error #252

Closed
hjdhnx opened this issue Feb 29, 2024 · 10 comments · Fixed by #227
Closed

require crypto-js.js commonJS runing error #252

hjdhnx opened this issue Feb 29, 2024 · 10 comments · Fixed by #227
Assignees

Comments

@hjdhnx
Copy link

hjdhnx commented Feb 29, 2024

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

windows11

Python version (python --version)

3.8.8

PythonMonkey version (pip show pythonmonkey)

0.3.0

Bug Description

I try to require crypto-js.js,but call it failed
my code is such as this:

from pythonmonkey import eval as js_eval, require as js_require
CryptoJS = js_require('./crypto-js')
text = CryptoJS.MD5('123456').toString()
print('md5 text:',text)
text = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse('123456'))
print('base64 text:',text)

md5 text get empty string
base64 text raise an error
image

test_file link is view here

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

@hjdhnx
Copy link
Author

hjdhnx commented Feb 29, 2024

from pythonmonkey import eval as js_eval, require as js_require
CryptoJS = js_require('./crypto-js')
text = CryptoJS.MD5('123456').toString()
print('md5 text:',text)
text = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse('123456'))
print('base64 text:',text) 

@hjdhnx
Copy link
Author

hjdhnx commented Feb 29, 2024

image
it's the same as npm require

@wesgarland
Copy link
Collaborator

wesgarland commented Feb 29, 2024

  • I can reproduce this with crypto-js 4.2.0
  • I used npm to install crypto-js so I had to change the require to not have the ./
  • this works properly if done in pure JS from pmjs, so the problem must be related to JS<>Python layer
npm init
npm i crypto-js
[~/test] dev-wes:wes# pmjs
Welcome to PythonMonkey v0.3.0.
Type ".help" for more information.
> CryptoJS = require('crypto-js')
...
> text = CryptoJS.MD5('123456').toString()
'e10adc3949ba59abbe56e057f20f883e'
> text = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse('123456'))
'MTIzNDU2'
> 

@wesgarland
Copy link
Collaborator

wesgarland commented Feb 29, 2024

~ minimal test case

npm init
npm i crypto-js
[~/test] dev-wes:wes# python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pythonmonkey import eval as js_eval, require as js_require
>>> CryptoJS = js_require('crypto-js')
>>> CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse('123456'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pythonmonkey.SpiderMonkeyError: Error in file evaluate, on line 59:
TypeError: map is undefined
Stack Trace: 
  stringify@evaluate:59:22

>>> 

@wesgarland
Copy link
Collaborator

In crypto-js/enc-base64.js, I think this is blowing up on line 59 because this._map in the stringify method is undefined.

This implies that PythonMonkey is invoking CryptoJS.enc.Base64.stringify with the wrong this

@wesgarland
Copy link
Collaborator

@hjdhnx - this is probably-fixed in PR 227. Stay tuned, I expect a new release in a week or two with that PR landed.

@zollqir
Copy link
Collaborator

zollqir commented Feb 29, 2024

I just tried @wesgarland's minimal test case on that branch, and it works great, so you have that to look forward to (as this is effectively a duplicate of #172) .

@wesgarland
Copy link
Collaborator

Confirmed fixed on main already as well - 0.3.1.dev39+67e65d0

@hjdhnx
Copy link
Author

hjdhnx commented Mar 1, 2024

Confirmed fixed on main already as well - 0.3.1.dev39+67e65d0

oh thank you for fix this bug, I test ok
image

@hjdhnx
Copy link
Author

hjdhnx commented Mar 1, 2024

pythonmonkey-0.3.1.dev42+6b5fb9d-cp38-cp38-win_amd64.whl fixed this bug

@hjdhnx hjdhnx closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants