creationix/http-parser-js

How to use with type module in Node v13

eAmin opened this issue · 4 comments

eAmin commented

Greetings

Is it possible to use it with type module system in Nodejs v13?

import HTTPParser from 'http-parser-js';

process.binding('http_parser').HTTPParser = HTTPParser;

Yes, that looks correct?

eAmin commented

Yes, that looks correct?

‌But it doesn't work.

It would be good to explain what isn't working if you want assistance...

Looking at the Node docs, probably actually need to do:

import httpParserModule from 'http-parser-js';
process.binding('http_parser').HTTPParser = httpParserModule.HTTPParser;

As the import statement pulls in the whole module.

Just did a quick test myself though, and it seems Node isn't allowing monkey-patching of the parser in a an ES module for some reason, so you'll probably have to use a standard Javascript file to load the replacement parser, do the monkey-patching and then run the rest of your program. Seems to still be working in at least Node v13.11.0 if not using the experimental modules.

eAmin commented

Just did a quick test myself though, and it seems Node isn't allowing monkey-patching of the parser in a an ES module for some reason, so you'll probably have to use a standard Javascript file to load the replacement parser, do the monkey-patching and then run the rest of your program. Seems to still be working in at least Node v13.11.0 if not using the experimental modules.

I've tested your code before, but it doesn't work too.
We should use CommonJS style module loading to achieve that, as you mentioned before.

Thanks.