Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
node-gyp on windows problem with UnicodeDecodeError

node-gyp on windows problem with UnicodeDecodeError

Reason

  • node-gyp writen in python
  • python have 2 mode for work with strings - unicode and ascii
  • node-gyp use ascii mode
  • windows use utf-8 for paths
  • python throw UnicodeDecodeError for chars out of range 0..127 (Cyrillic chars for example)

Stacktrace example

Traceback (most recent call last):
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 50, in <module>
    sys.exit(gyp.script_main())
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 554, in script_main
    return main(sys.argv[1:])
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 547, in main
    return gyp_main(args)
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 532, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 2019, in GenerateOutput         File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 954, in _GenerateProject          return _GenerateMSBuildProject(project, options, version, generator_flags)
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 3400, in _GenerateMSBuildProject
    easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True)
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\easy_xml.py", line 123, in WriteXmlIfChanged
    xml_string = xml_string.encode(encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 2691: ordinal not in range(128)

Solution

  • Exclude dirs with non latin chars
  • node-gyp use os home dir for store node C headers, change it:
npm config set --global devdir D:\node-gyp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment