Using nodejs modules in next.js - node.js

I facing a problem with nodejs module not working in my nextjs app. Any help would be appreciated
I'm importing it like this
import {saveAs} from "file-saver";
Module not found

It seems as though you don't have the module installed, to verify it's installed, run the following:
With NPM:
npm install file-saver
With Yarn:
yarn add file-saver

Related

React version issue. Not able to upgrade version

I am not able to install latest version of react. Actually I installed a particlar version after appending # , after that what ever I am doing it is not working. even I unistalled nodejs completely. still it is not working.
npm react --version
6.14.15
Then I ran this
npm install --save react#latest
After that version is still coming same.
npm react --version
6.14.15
After that I uninstalled react using below
npm uninstall -g create-react-app
I also did
npm uninstall react
and then checked the version. it is still coming same.
I followed onw blog and tried below. still it dint work.
npm install react-scripts#4.0.0 react#17.0.0 react-dom#17.0.0
and installed react again. still it is giving same version.
Could you please help me on the same.
Is there any to remove it completely from the system?
Let understand the diff between react and create react app.
React is a js library for creating user interfaces but and create react app is a cli tool that help us to create the files template for a react project and both are totally different npm packages.
The create react app doesn't depend on react so it doesn't install the required version of react.
If you want to upgrade your react library you have to install react
npm i -g react#latest

Can't update dependency library when code was changed in npm

I just started project react native. I created react native module by command npm install react-native-my-library --save, then run npm install I see it exist in node_module folder.
But when I change code in react native module, and remove folder node_module and run npm install again to update in node_module, it also doesn't update new code that I changed in native module.
Any body can help me to update code in node module folder.
Thanks so much!

react-router 3.10.10 IndexRoute

I'm trying to figure out how to build apps with react and feathers. I found Ben Awad's YouTube tutorial series (https://www.youtube.com/watch?v=etq_vv_RVcU&index=2&list=PLN3n1USn4xlnulnnBGD2RMid_p7xVj9xU) and was following along with the code. However I somehow got an issue he didn't cover. When I go to run the code produced at the end of this video I get the following error:
./src/index.js
36:23-33 'react-router' does not contain an export named 'IndexRoute'.
Most of the stuff I've found seems to suggest that IndexRoute was phased out in v4, however running npm -v react-route returns 3.10.10 so I don't think it should be affected (could be wrong). Does anyone have any thoughts about what might be causing this issue? Thank you.
I think IndexRoute was removed since version 2 from react-route so you must use version 2 of react-route, in order to do so you can install it using npm:
npm install --save react-router#2
IndexRoute was removed in version 4 meaning that version 3.x still has it. Install with npm:
npm install --save react-router#3.x
or
yarn add react-router#3.x

get error when trying to use twilio's npm package in meteor

I am trying to use the twilio node.js library with my meteor application. I was able to install the package using meteor npm install --save twilio
and it installed correctly. However, when I use import twilio from 'twilio'; I get this error
Error: Cannot find module 'crypto'(…)require # modules-runtime.js?hash=637cb12…:119meteorInstall.node_modules.twilio.lib.webhooks.js # modules.js?hash=9468cd4…:38774fileEvaluate # modules-runtime.js?hash=637cb12…:191require # modules-runtime.js?
Any thoughts on how to fix this. Seems to be a meteor error.
Normally, when you hit the command meteor npm install it should create a folder name meteor-node-stubs (/node_modules/meteor-node-stubs) in which the dependencies such as crypto etc. is arranged.
I think there is a problem with this folder in your project. My suggestion is to check whether you have this folder.
If you do not have it, you can try to install it by meteor npm install --save meteor-node-stubs That should solve your problem if this is the case

Using NodeJS plugins in Electron

I am new to Electron (Atom-shell), and I am trying to load a NodeJS plugin into the application I am building, but I don't know how. The documentation is not clear on that.
For instance, I am trying to use sqlite3 plugin in my app, I used npm install sqlite3, and it was successfully installed. But the application throws and error when I try to call it var sqlite = require('sqlite3'). Are there any further steps I am not aware of ?
Thanks.
For pure JS (i.e. not native) modules you need the following:
Have the module listed in your package.json dependencies
Let electron know where to find the module (e.g. export NODE_PATH=/PATH/TO/node_module)
The first requirement is obvious and the second has its roots in this issue.
For native node modules (such as sqlite3) which use C++ bindings, you need to build them against electron headers to work. According to electron docs, the easiest way to do that would be:
npm install --save-dev electron-rebuild
# Every time you run npm install, run this
./node_modules/.bin/electron-rebuild
To install the npm modules correctly you should go into the folder of your electron app and install the module via npm.
npm install --save sqlite3
The flag --save is important, because npm will install the module inside your app.
Afterwards the require should work.

Resources