Jint.CommonJS icon indicating copy to clipboard operation
Jint.CommonJS copied to clipboard

node Require

Open bgribaudo opened this issue 4 years ago • 2 comments

Hello,

Thank you for providing this extension to Jint!

You are not able to load npm packages with Jint.CommonJS. Although the library loads modules in relatively the same format at NodeJS's Module specification, there are some important distinctions. The library does not support node_modules, or reading package.json files for modules.

Do you know of any Jint extension that can handle basic node requires (no package.json)?

Thanks, Ben

bgribaudo avatar Jun 02 '20 19:06 bgribaudo

Hi Ben,

Apologies for the hiatus and delayed reply, although unfortunately you may not derive too much use out of this either way.

Do you know of any Jint extension that can handle basic node requires (no package.json)?

Basic node requires is exactly what the library does, as Jint.CommonJS and node.JS both implement the CommonJS spec with a few important distinctions which I think you might have your wires crossed with. Jint.CommonJS doesn't support node_modules not because of arbitrary decision, but because Jint.NET isn't node.js: NPM modules assume the presence of a node.js or browser environment which will never work unless you specifically emulate an entire node.js runtime (the presence of the process global, require('fs'), the Window global et al) or almost every module loaded via Jint.CommonJS will fail to execute.

However, Jint.CommonJS will happily load from a node_modules path if it's specified directly so I'm curious as to your use case.

Cheers, Tyler.

tylerjwatson avatar Jun 25 '20 23:06 tylerjwatson

Thanks, @tylerjwatson. My apologies for the long delayed reply, as well. :-)

I had been trying to use Jint.Net to load https://github.com/Microsoft/powerquery-parser then do a simple parse (like something from https://github.com/microsoft/powerquery-parser/blob/master/src/example.ts). Startup would die due to being unable to load all the requires....

bgribaudo avatar Jun 21 '21 17:06 bgribaudo