Require path in nodejs frappe - node.js

So I am experimenting with nodejs, and have chosen frappe as a skeleton for learning (as I already use coffeescript on the frontend blah blah blah). Anyway I am just getting started and have encountered a problem, so noobish, I can't find an answer on google. The picture above should say it all.
What is wrong with my path to /config/globals ? I have tried:
./config/globals
/config/globals
globals
To no avail. What am I missing here?

path should be ./globals since you require a file from the same directory.
../config/globals would also work.
A require value with no path information looks for a module loaded by npm either locally inside node_modules, or in the global npm location.

Related

Problems exporting a functional component in a ReactJS Module

I'm having problems importing my functional component BusinessCard (declared here https://github.com/HenryFBP/react-business-card-hfbp/blob/master/src/BusinessCard.tsx#L20)
into a different project (here https://github.com/HenryFBP/personal-website-react/blob/master/src/pages/PageContact.tsx#L3).
I used npm link react-business-card-hfbp, and I can see the symlinked folder, but I must be doing the export incorrectly or don't understand package.json.
I have also tried installing from https://www.npmjs.com/package/react-business-card-hfbp/ but that does not seem to work either.
The error (below) from webpack is Module '"react-business-card-hfbp"' has no exported member 'BusinessCard'.. I tried so many different combinations, edited package.json quite a lot, but I am stuck on this.
I'm sure the answer is simple, I just don't have enough experience with Node Modules to understand what is going on.
Thanks so much <3
I fixed it! With the help of a kind person on "Reactiflux" Discord server.
TL;DR: I was not compiling it into a module correctly. I should have used parcel to compile it into a module. I thought that TypeScript could be included in modules - this is apparently not correct, you must somehow turn it all into JavaScript first.
Working code:
npm run build
npm publish
Working package.json:
https://github.com/HenryFBP/react-business-card-hfbp/blob/master/package.json#L42

"cannot find module npm-cli.js"

I've been at this for hours, and I've tried endless things and reinstalled NodeJS so, so many times.
I'm on Win10. I cannot run npm, it seems to have some PATH error I cannot get around this:
Error: Cannot find module 'C:\Program
Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
This path looks screwy, I know. I've removed any roaming entries in the PATH var for nodejs or npm. Only
C:\Program Files\nodejs
remains at this point.
Is there any real solution that works for Win10 every time?
I'll do anything at this point. I've tried so, so many things that I found here or a dozen other sites.
I'm not trying to do anything special. I just want to run npm at the command line successfully--update itself, check itself, anything. No matter how it's invoked, I get the error above.
I mean, what should the PATH look like? How can I make this thing happy?
Thanks for any help.

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.

Seriously debugging node.js 'Cannot find module xyz/abcd'

I have the Error: Cannot find module xyz/abcd error.
YES, the required module is installed.
According to the pseudo-code of module.require here, it should work.
I tried to dive inside require() to understand why it can't find my file. My node debugger won't step into require(). I've tried the strace / grep NOENT technique whithout success either.
Any idea how to troubleshoot a nasty require() failure ?
Note : just in case : the error comes from a file node_modules/xyz/a requiring xyz/b. It should work according to the doc.
By investigating more, I think I found a good technique :
export NODE_DEBUG=module
node my_script.js
gives such interesting traces :
looking for "/(...)/tests_init.js" in ["/home/(me)/.nave/installed/0.10.24/lib/node","/home/(me)/.node_modules","/home/(me)/.node_libraries","/home/(me)/.nave/installed/0.10.24/lib/node"]
And BTW, it shows that node is not searching at all where I thought it was. Time to investigate...
[edit] end of the story :
1) it appears that node is not treating well modules installed with npm link. require(...) sometimes fails to select files from inside a npm-linked module. I have no desire to investigate further the exact error conditions, I'll just conclude that npm link is very brittle.
2) beware of node looking for node_modules all the way into the parent dirs of current working directory ! I found that modules from parent folders of my app where sometime selected !

node jitsu cannot find local modules

I have an application successfully working locally so I know the code works. However when I go to deploy to node jitsu I get an error that it cannot find a local module. Here is what I have:
File Setup:
/index.js
/config/config.js
index.js
var cfg = require('./config/config.js');
When trying to deploy node jitsu is giving me an error:
Error: Cannot find module './config/config.js'
Since all this code works locally I do not believe this is a coding issue. I am under the impression that local modules do not need to be included in package.json but perhaps they do for node jitsu? I read their documentation but cannot find anything special for local modules.
Thanks!
Local modules like this should work properly.. so long as you don't have it in .gitignore or .npmignore.
Modules in the node_modules directory require that you add it to the bundledDependencies array in your package.json file.
An easy way to check for whether the file is included in your deploy is to run tar -tf $(npm pack).
I had this exact same error on deploy, but caused by a different root cause. In case anybody stumbles into the same problem:
File Setup:
/public/Data/TargetData.js
app.js require statement:
var target = require('./public/data/TargetData.js');
My local Mac OSX environment allowed the capitalization difference of /data/ vs. /Data/ - the Nodejitsu server did not.

Resources