How to tweak an existing nodejs module and use it outside node_modules folder? - node.js

I'm using the module node-libcurl. When I deploy my app to Heroku it crashes when I initiate a function from the module (that works on my computer).
Thus I would like to add some logging to the existing node-libcurl module to troubleshoot the issue, and put it in my lib folder outside the node_modules (I excluded it from the git heroku repo).
I added node-pre-gyp lib to the node_modules explicitly.
For information the error is self-explanatory:
Error: getInfo failed. Error: An unknown option was passed in to libcurl
at Curl.getInfo (/app/node_modules/node-libcurl/lib/Curl.js:1023:15)
at Object.keys.filter.forEach.key (/app/src/libs/node-libcurl-promise.js:70:23)
at Array.forEach (<anonymous>)
at Curl.curl.on (/app/src/libs/node-libcurl-promise.js:69:6)
at emitThree (events.js:136:13)
at Curl.emit (events.js:217:7)
at Curl._onEnd (/app/node_modules/node-libcurl/lib/Curl.js:929:10)
at Multi.<anonymous> (/app/node_modules/node-libcurl/lib/Curl.js:52:14)
I would like to figure out what is the option that I set and that doesn't work
on Heroku and that works on my computer.
Thank you!

The key might be in the error messase: An unknown option was passed in to libcurl. It implies that libcurl was told to set/use an option that it doesn't know about. Probably because it is (too) old so your code is using an option that was added to a newer libcurl version and node-libcurl was built to use one or more of those newer options that your older libcurl doesn't know about!

Related

NodeJS require doesn't work. Cannot import downloaded npm modules

I have a slight problem with a basic Node.JS method. When I'm trying to use "require()' method to import any downloaded (with 'npm install ..) module/library, I get a Visual Studio Code message that asks 'to convert 'require'(which is a Common JS module) into ES. If I do it, it transforms 'require()' into 'import..' though I want keep using 'require()'. Why is it so ? I read somewhere that Common JS is already included in the Node.JS environment though.
Then, when trying to compile my index.js file (with 'node index.js'), I obviously get an error about 'require' not recognized method.
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users...index.js from C:\Users...index.js not supported.
I tried then to install Webpack to fix this issue, but nothing change. I also kind of installed CommonJS (npm i common-js)..
Another common answer was to remove 'type':'module' from package.json file which normally should allow to use 'require', but I don't even have such a line in the file.
On top of that I've recently read that 'require' is not compatible with browser development tools (it's ok). But I'm trying to import a downloaded module/npm package in VSC terminal, not even in a browser.
As you understand I'm new to Node.JS, but I don't really get what's going on in this case...

Node.js module is looking for node-modules instead of node_modules

I have the following based on instructions from here:
const Pubgapi = require('pubg-api');
const apiInstance = new Pubgapi('api-key');
For some reason when I run it, the console says unable to resolve path but it's looking for a node-modules which I don't have. This is an API wrapper that I am trying to use by the way. What could cause it to give me this error?
I did an npm install as the instructions said and nothing else before the statements above.
Error message:
Unable to resolve ../node-modules/pubg-api" from ".//components/Main.js`: The module `../node-modules/pubg-api` could not be found"
I have checked the node_modules folder. It is indeed pubg-api, not pubg_api. Requiring pubg_api gives me this error.
This error is probably related to the HTTPS library that the library you are trying to install depends on. Node.js libraries are not compatible with react-native since it is not working on a Node.js platform.
To overcome this issue you can try to use react-native-http library, but I did not try to use it before, so I'm not sure if it's going to work or not.

react-native attempting to resolve built-in fetch function

I'm attempting to use the fetch function in react-native to grab a piece of data from the web. from what I understand reading the docs, the fetch function is built in to react-native.
when doing so, I get the module resolution error in the attached screenshot, where for whatever reason the react-native bundler is attempting to use the fetch provided by typescript from my ~/.cache directory.
I've previously had typescript 2.6 installed globally via npm, I uninstalled it to see if that might fix things, but the error persists.
I should note that the only things I've done for this project are to create it with create-react-native-app, add a little snippet to the App.js component stolen from the react docs to fetch some JSON, and yarn run eject the project (this error persisted before and after the ejection)
well in my turkey-induced frenzy, it appears I hadn't properly uninstalled the global typescript install on my computer.
having done so properly, the issue is resolved;
however the issue of react-native's module resolution strategy being incompatible with a global typescript installation persists.

Unable to import native nodejs module in electron project

I'm working on an open source electron project which I am building using webpack. One requirement for my project is to use the nodegit library which has to be built as a native module.
I've followed what appears to be conventional advice when working with native modules and electron. That is, I run electron-rebuild, have configured the source package to use and finally have configured node-loader to catch the import of any .node files.
Unfortunately, when I go to include the module, I end up with this error:
ERROR in ./node_modules/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../build/Debug/nodegit.node' in
'C:\Users\atrauzzi\Development\atrauzzi\gerty\node_modules\nodegit\dist'
# ./node_modules/nodegit/dist/nodegit.js 18:11-49
# ./src/Layer/Domain/Thunktor/Git/CloneGitRepository.ts
# ./src/Layer/Gerty/Component/Repository/AddGitHubRepository.tsx
# ./src/Layer/Gerty/Component/Repository/AddRepository.tsx
# ./src/Layer/Gerty/Component/Workspace.tsx
# ./src/Layer/Gerty/Component/App.tsx
# ./src/Layer/Gerty/GertyServiceProvider.ts
# ./src/Bundle/GertyElectron.ts
The only thing I can see that's suspicious at this point is that when I rebuild the module to work with electron, I only get a Release directory, when the import seems to be looking for Debug:
This could be a red herring however as nodegit is written to try Debug as a fallback after Release has failed.
The general ask here is "How do I get this native module working in my project?".
I also have a corresponding question over at the repo, although on the off chance that my issue is unrelated to the library itself, or that there are some battle-worn veterans of native modules in electron, I figured SO would be a good place to check as well.
Try configuring your webpack by specifying the native module as an external dependancy rather than load it using the node-loader.
https://webpack.js.org/configuration/externals/

brunch.io not handling compilation errors

I created my own brunch configuration to work with coffeescript, jade and stylus.
It works perfectly, except for one major issue. Whenever coffeescript or jade (not had a stylus coding error yet) have issues compiling during brunch --watch, I get an error like the following :
C:\path\to\node_modules\brunch\lib\fs_utils\pipeline.js:64
return callback(throwError('Compiling', error));
^
ReferenceError: callback is not defined
at C:\path\to\node_modules\brunch\lib\fs_utils\pipeline.js:64:18
at CoffeeScriptCompiler.module.exports.CoffeeScriptCompiler.compile (C:\path\to\node_modules\coffee-script-brunch\lib\index.js:56:16)
at C:\path\to\node_modules\brunch\lib\fs_utils\pipeline.js:93:31
at fn (C:\path\to\node_modules\brunch\node_modules\async-waterfall\index.js:19:24)
at Object._onImmediate (C:\path\to\chromesign\node_modules\brunch\node_modules\async-waterfall\index.js:58:22)
at processImmediate [as _immediateCallback] (timers.js:330:15)
It looks like the plugin should be passed an error call back, but it isn't happening?
Have I done something wrong in my configuration? The skeleton with all the config is hosted on GitHub. I'd appreciate some input as to whether this is a problem on my side!
Thanks!
It appears that you installed brunch from the git master branch when you generated this error. I was unable to reproduce it using v1.7.10. On master (where I was able to reproduce it), it's just been fixed with https://github.com/brunch/brunch/commit/68dd9c9b6284c05a4eb01050dba56f80f978e35a. So if you reinstall brunch now, either the latest release (1.7.10) or the edge version from git master, the problem you've reported should go away.
Additionally, you might want to reconsider making brunch a dependency of your skeleton in the package.json. Unless there's a specific reason otherwise, it's better to let it just be installed globally. If you want to clarify to users that your skeleton should only be used with brunch versions >=1.7, you can say so in your readme.

Resources