package.json file created in the wrong folder - npm

I am creating an app to work with an API using serverless, and the initial install was ok. One of the folders that the npm serverless install does is auth-server, where two files - handler.js and serverless.yml are created (other than the .gitignore).
A few steps later, I had to install Axios as I will need to make a POST request for the API. Being on the auth-server directory, I ran the usual npm syntax to install Axios, npm install axios. To my surprise, however, npm has not created the package.json (and package-lock.json) file within the auth-server folder but used the root files.
I tried to look around to see if the problem was recurrent, but found nothing. I know that package-json file is created within the directory folder from where npm is executed as I have used axios a few times. Can someone point me where the problem may lie? Thanks in advance.

In case someone else needs this: I found out that although not in all cases, it is not uncommon that the npm will use the package.json file of the root folder. As I needed it inside the auth-server folder, I simply created another package.json file inside it (with a pair of curly brackets on it to avoid a parse error code EJSONPARSE) and saved it. Once I installed Axios one more (npm install axios) the package.json file began to be used and added Axios as a dependency.

Related

Blazor Javascript isolation with NPM dependencies

I'm trying to use the new Blazor Javascript isolation feature. I'm importing my own JS file as per the example ExampleJsInterop.cs. It works until I try to import an NPM module from within my script. In my package.json I have set up a dependency on interactjs, and in my script I have added import interact from 'interactjs'; at the top.
I'm getting a Failed to resolve module specifier "interactjs" error. I'm not sure how to get past that.
Previously I was using Webpack to bundle my script and dependencies together into a single file that is added into my index.html as a tag. This was working fine, but I'm not sure how to continue using NPM packages with JS isolation.
Thanks!
A bit late, but I've just finished solving a similar issue.
The npm files are installed to the hidden node_modules folder. This isn't available to your script when you are running your app, unless you do something to make it available. however, even if you copied the interactjs file into your scripts folder it would still not work if it was an npm file. Those are meant to run in nodejs not a browser. So you would still need to use your bundler. I tried webpack, but had some issues with certain files so ended up with snowpack instead. I just finished a bunch of articles on javascript interop - part 4 deals with npm
I forgot that I left this question open for almost a year!
I ended up solving it using Snowpack to bundle the NPM package into the Blazor wwwroot folder. Credit goes to this article for pointing me in the right direction: https://nbarraud.github.io/js-in-blazor.html

How to change src code of Vue in node_modules for testing

I am using Vue 2 (doesn't really matter which version exactly).
I want to test some things that happen behind the hood in Vue. So I decided to add console.log('test123') in Vue's files in node_modules. It turns out that the console log never fires. I put that in all files of Vue in node_modules, even in all files of dist's folder of Vue.
How can I achieve this ? If I fork the repo, then I'd have to upload new versions each time on my repo and then run npm install. I know that will work but wanted to achieve this without forking.
Any ideas what I am missing ?
there are many ways .. but i feel more comfortable using this method :
you can download any npm package in a seperated folder next to your project...
open the folder of the package then run this in the terminal:
npm link
then open the project folder and run
npm link ../package-path # link the dir of your dependency
References
npm-link
How to test an npm package locally

How to let npm use sass which comes from local libsass-dev(installed by apt) instead of downloading its own package?

I have a libsass-dev on my system. But npm will download its own one, which is annoying. How to let npm makes use of libsass-dev?
You can try specifying the absolute path to your module, assuming is outside the node_modules folder.
You can try first the require.resolve('/path/to/my/Module') and if it finds it will return the path to the module, then do the require function.
Or You can create your own folder inside node_modules and require the full folder, something like require('./relativeOrAbsPath/To/My/node_modules/myModule'). The default file is index.js or You can mention in the package.json file using the main property to specify another file name.
Also you can update your modules path using this npm module https://www.npmjs.com/package/app-module-path but this looks first on your node_modules folder. However on prior version 1.x is starting for the bottom of the module.paths list.

Peer dependency that is also dev dependency of linked npm module is acting as a separate instance

In my app, I have these dependencies:
TypeORM
typeorm-linq-repository AS A LOCAL INSTALL ("typeorm-linq-repository": "file:../../../IRCraziestTaxi/typeorm-linq-repository"), who has a dev dependency AND a peer dependency of TypeORM
The reason I use a "file:" installation of typeorm-linq-repository is that I am the developer and test changes in this app prior to pushing releases to npm.
I was previously using node ~6.10 (npm ~4), so when I used the "file:" installation, it just copied the published files over, which is what I want.
However, after upgrading to node 8.11.3 (npm 5.6.0), it now links the folder rather than copying the published files.
Note, if it matters, that my environment is Windows.
The problem is this: since both my app and the linked typeorm-linq-repository have TypeORM in their own node_modules folders, TypeORM is being treated as a separate "instance" of the module in each app.
Therefore, after creating a connection in the main app, when the code that accesses the connection in typeorm-linq-repository is reached, it throws an error of Connection "default" was not found..
I have searched tirelessly for a solution to this. I have tried --preserve-symlinks, but that does not work.
The only way for me to make this work right now is to manually create the folder in my app's node_modules and copy applicable files over, which is a huge pain.
How can I either tell npm to NOT symlink the "file:" installation or get it to use the same instance of the TypeORM module?
I made it work pretty easily, although I feel like it's kind of a band-aid. I will post the answer here to help anybody else who may be having this issue, but if anybody has a more proper solution, feel free to answer and I will accept.
The trick was to link my app's installation of TypeORM to the TypeORM folder in my other linked dependency's node_modules folder.
...,
"typeorm": "file:../../../IRCraziestTaxi/typeorm-linq-repository/node_modules/typeorm",
"typeorm-linq-repository": "file:../../../IRCraziestTaxi/typeorm-linq-repository",
...

Steps to create node-js client kurento opencv module

What I do :
1.I used the opencv-plugin-sample(from the link https://github.com/Kurento/kms-opencv-plugin-sample) and start the kuretoMediaServer
2.In the client side I used js and java,Both works well
3.For js I used the command
cmake .. -DGENERATE_JS_CLIENT_PROJECT=TRUE
npm install grunt grunt-browserify grunt-contrib-clean grunt-jsdoc grunt-npm2bower-sync minifyify
grunt
to generate the js folder and the dist folder
4.For java I used the command
cmake .. -DGENERATE_JAVA_CLIENT_PROJECT=TRUE
make java_install
What I have to do:
1.Now I need to run kurento with android,So I have used the following link https://github.com/apeunit/AppRTC-Kurento-Example
2.In the client side they have used node-js to communicate with KMS
3.Now I am trying to add the opencv sample in the existing code,With reference to the link http://doc-kurento.readthedocs.org/en/stable/mastering/develop_kurento_modules.html#examples ,I changed the package.json file but it shows the error
'kurento-module-opencvpluginsample' is not in the npm registry.
4.When I checked the crowd-detector sample(https://github.com/Kurento/kurento-tutorial-node/tree/master/kurento-crowddetector ) ,module(kurento-module-crowddetector) is present in the node_module folder,For the opencv-sample
Whether I need to add the module(kurento-module-opencvpluginsample) maually?or
Is there any default steps to generate files in the module(kurento-module-opencvpluginsample) folder as done in java and js above?
npm resolves packages by name and version by checking with the npm registry (see this link for more info) What this line
kurento-module-opencvpluginsample' is not in the npm registry.
is telling you, is that it cannot find your module in the npm registry. That's no surprise, as it is only located in your local machine. Please have a look at this SO answer about how to specify local modules as npm deps.