Getting error Cannot find module 'crypto' - node.js

I am trying to use node Crypto module in Angular 7 for asymmetric encryption.
and used below command to import the Crypto module
import * as crypto from 'crypto';
but still I am getting error that is
`ERROR in src/app/log-in/log-in.component.ts(11,25): error TS2307: Cannot find module 'crypto'.`
Please help me to resolve the error that how to use this library into Angular.
Thanks in Advance.

I was trying to import { randomBytes } from "crypto"; then such error occurred,
I installed node types npm install #types/node --save-dev and it was resolved.

Per the author on npm , The crypto package is no longer available as it is now built in to Node.js. I would suggest looking for an alternative. I came across a Github Gist that contains some suggestions: https://gist.github.com/jo/8619441
Make sure whatever you pick is useable in the browser. Some of the options listed there are server-side only.

Make sure that you install 'crypto' module from npm
use: npm i crypto to install this module.
for more information please visit here.
If this is still not working then you have to check for alternative module because this module is dedicated you can check this

Related

NodeJS-MSMQ: SyntaxError: Cannot use import statement outside a module

I'm pretty new with NodeJS and I'm trying to use a module called "updated-node-msmq" (from this repository) in my project but getting an error.
What I've done:
I opened a new folder for the project.
I used the command "$ npm install --save updated-node-msmq" and got some warnings (Screenshot attached).
When I try to use the module according to the README, and run my "test.js" file I got the following error here in the screenshot).
I am using version 14.16.0 of NodeJS and after trying to fix this myself I realized that probably the problem is that the module was built for older versions of NodeJS.
I understand that low version is not a recommended solution, but I have no clue how to update a module.
Help / guidance in solving the problem?
Thanks in advance everyone!
Why are you using updated-node-msmq? That package seems like a mess, and the errors you are getting is because the whole module is written with ES2015 but doesn't seem to have been transpiled to node.js compatible code before published to NPM.
I'd advise you to use a tried and tested module for MSMQ first and foremost.
EDIT: Seems like the author fucked up in the 0.2.0 version. You could use the 0.1.9 (by instead using npm install updated-node-msmq#0.1.9 but that one is 3 years old.

Error importing 'vscode-languageserver' in a React app

I am trying to create a playground using monaco-editor and vscode-languageserver to show the features of my language server.
However when I try to import 'vscode-languageserver' from a page like the following example
//# src/pages/test.js
const { TextDocument } = require("vscode-languageserver");
console.log(TextDocument.create('a' , 'b' , 'c' , 'd' ));
https://github.com/zkrami/docusaurus-test/blob/master/src/pages/test.js
I get the following errors:
Module not found: Can't resolve 'child_process' in 'C:\Users\Rami\git\my-website\node_modules\vscode-languageserver\lib'./node_modules/vscode-languageserver/lib/files.js
Module not found: Can't resolve 'fs' in 'C:\Users\Rami\git\my-website\node_modules\vscode-languageserver\lib'./node_modules/vscode-jsonrpc/lib/pipeSupport.js
and please note that if I imported the module in the docusaurus.config.js file it works perfectly.
I made a quick example you can try:
https://github.com/zkrami/docusaurus-test/
Specifications:
yarn 1.22.4
node v10.15.3
OS: Windows
#docusaurus/core: "^2.0.0-alpha.54"
I ended up using vscode-languageserver-protocol package which fulfill my requirements.
fs is a Node module and requires Node runtime, you can't use it in the browser.
This is not a Docusaurus issue, you wouldn't be able to use it in any client-side React app.

Using request with Gatsby

I am trying to add the request module to fetch some data, but I am having trouble, given, that it somehow relies on the fs module
Installing it and requiring it lands me this error:
This dependency was not found: fs, tls, net
To install it, you can run: npm install --save fs tls net
Installing tls and net seems to fix them (as they don't appear after that) but the fs issue remains. I've checked multiple issues about Webpack and request, but modifying my webpack config didn't help much.
How can I get request to work in a Gatsby website?
Thank you and good day
Request doesn't work on the frontend.
Use https://github.com/axios/axios instead.

npm replacement for fs module

how can i find a replacement for fs?
i am using the itunes APN from npm (npm install apn) but it uses the fs module. I spend many hours on research and some suggested i had this to my webpack config
node: {
'fs': empty
}
this prevents any errors but it obviously breaks the code so as far as i am concerned is not a solution at all.
I tried using fs-extra but this requires graceful-fs which in turns requires again the good old 'fs' module. So we are going in circles. How can i solve this please?

Any way to use pandorabots node module with Nativescript?

They have a Pandorabots API module for Node.js. After installing it and runnig the app I get Could not find module 'fs'. Thank you for any insight.
Thanks for asking
I have studied whole pandorabots docs but did not get any error like you are getting and my given code can only solve the problem for "fs"
if you are interested then, you can use that
$ npm install fs --save
var fs =require('fs');

Resources