Skip to content

require crypto-js.js commonJS runing error #252

Closed

Description

@hjdhnx

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

Activity

  1. hjdhnx commented on Feb 29, 2024

    @hjdhnx
    Author
    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) 
  2. hjdhnx commented on Feb 29, 2024

    @hjdhnx
    Author

    image
    it's the same as npm require

  3. wesgarland commented on Feb 29, 2024

    @wesgarland
    Collaborator
    • 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'
    > 
    
  4. wesgarland commented on Feb 29, 2024

    @wesgarland
    Collaborator

    ~ 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
    
    >>> 
    
  5. wesgarland commented on Feb 29, 2024

    @wesgarland
    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

  6. wesgarland commented on Feb 29, 2024

    @wesgarland
    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.

  7. zollqir commented on Feb 29, 2024

    @zollqir
    Collaborator

    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) .

  8. wesgarland commented on Feb 29, 2024

    @wesgarland
    Collaborator

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

  9. hjdhnx commented on Mar 1, 2024

    @hjdhnx
    Author

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

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

  10. hjdhnx commented on Mar 1, 2024

    @hjdhnx
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions