npm install node-geocoder issue while running npm run build in type script + PCF (Powerapps Component Framework) - node.js

I have created a PCF (Powerapps Component Framework) in which I am using the GEOCODE feature. I have installed the required components using "npm install node-geocoder" and have added the below code :
let nodeGeocoder = require('node-geocoder');
let options = {
provider: 'openstreetmap'
};
let geoCoder = nodeGeocoder(options);
geoCoder.geocode('Luray Caverns')
.then((res)=> {
console.log(res[0].latitude);
console.log(res[0].longitude);
})
.catch((err)=> {
console.log(err);
});
When i build this code using "npm run build", the build fails with following error:
ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in 'D:\PCF\Demo\node_modules\request\lib'
Module not found: Error: Can't resolve 'net' in 'D:\PCF\Demo\node_modules\forever-agent'
ERROR in ./node_modules/node-geocoder/lib/geocoder/agolgeocoder.js
Module not found: Error: Can't resolve 'net' in 'D:\PCF\Demo\node_modules\node-geocoder\lib\geocoder'
ERROR in ./node_modules/node-geocoder/lib/geocoder/datasciencetoolkitgeocoder.js
Module not found: Error: Can't resolve 'net' in 'D:\PCF\Demo\node_modules\node-geocoder\lib\geocoder'
ERROR in ./node_modules/node-geocoder/lib/geocoder/abstractgeocoder.js
Module not found: Error: Can't resolve 'net' in 'D:\PCF\Demo\node_modules\node-geocoder\lib\geocoder'
Any help would be helpful.
Thanks in advance.

Related

Error: Module not found: Error: Can't resolve src/app/app.component.css?ngResource Angular

I'm facing this 3 problems that I still can't understand where your mistakes are.
Error: Module not found: Error: Can't resolve 'C:/Users/DexSh/desktop/C# Angular/Testing/src/app/app.component.css?ngResource' in 'C:\Users\DexSh\desktop\C# Angular\Testing'
Error: Module not found: Error: Can't resolve 'C:\Users\DexSh\desktop\C# Angular\Testing\node_modules\webpack-dev-server\client\index.js?protocol=auto%3A&username=&password=&hostname=0.0.0.0&port=0&pathname=%2Fng-cli-ws&logging=info&overlay=%7B%22errors%22%3Atrue%2C%22warnings%22%3Afalse%7D&reconnect=10&hot=false&live-reload=true' in 'C:\Users\DexSh\desktop\C# Angular\Testing'
Error: The loader "C:/Users/DexSh/desktop/C# Angular/Testing/src/app/app.component.css" didn't return a string.
when using ng build returns this
Warning: ▲ [WARNING] Comments in CSS use "/* ... */" instead of "//" [js-comment-in-css]
C:/Users/DexSh/desktop/C# Angular/Testing/src/app/app.component.css:1:18:
1 │ /******/ (() => { // webpackBootstrap
╵ ~~
Warning: ▲ [WARNING] Unexpected "(" [css-syntax-error]
C:/Users/DexSh/desktop/C# Angular/Testing/src/app/app.component.css:1:9:
1 │ /******/ (() => { // webpackBootstrap
╵ ^
Error: Module not found: Error: Can't resolve 'C:/Users/DexSh/desktop/C# Angular/Testing/src/app/app.component.css?ngResource' in 'C:\Users\DexSh\desktop\C# Angular\Testing'
Error: The loader "C:/Users/DexSh/desktop/C# Angular/Testing/src/app/app.component.css" didn't return a string.
Can anyone tell me what's causing this, it's in every project
Waiting for a normal build and project execution
The problem is that you have a # in your folder name -> (C# Angular).
This f. problem made me to go on rampage too...

Runing nodegit in Electron fails

I installed nodegit 0.26.5 via npm and import the package in the renderer part of my Electron application. During compilation I receive this error below:
WARNING in ./node_modules/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../build/Release/nodegit.node' in '/Users/steve/Documents/git/git_reader/node_modules/nodegit/dist'
ERROR in ./node_modules/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../build/Debug/nodegit.node' in '/Users/steve/Documents/git/git_reader/node_modules/nodegit/dist'
ERROR in ./node_modules/nodegit/dist/nodegit.js
Module not found: Error: Can't resolve '../package' in '/Users/steve/Documents/git/git_reader/node_modules/nodegit/dist'
In my node_modules/nodegit/build directory, I only have a Release directory. Does anyone have an idea what I miss here?
I created a repo, which I forked from a boilerplate template. I only added nodegit and #types/nodegit as a dependency and imported it in details.component.ts
https://github.com/Githubber2021/electron-nodegit-error
git clone https://github.com/Githubber2021/electron-nodegit-error.git
npm install
npm run electron:local
to reproduce the issue. Can anyone reproduce the error on their machine? What am I missing here? Thank you so much for any help or hint!!
I'm using nodegit 0.27 and the error message for me was slightly different, it was
nodegit.js:1088 Uncaught Error: Cannot find module '../package'
Note that I'm using webpack together with electron forge and in my package.json I have the following. (I replaced the irrelevant parts with ...)
{
"name": ...
"version": ...
"description": ...
"config": {
"forge": {
"packagerConfig": {},
"makers": [
...
],
"plugins": [
[
"#electron-forge/plugin-webpack",
{
"mainConfig": ...
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
...
]
}
}
]
]
}
},
...
}
And in my webpack.renderer.config.js I needed to add an externals field to my exports so that they look something like this
module.exports = {
...
externals: {
nodegit: 'commonjs nodegit'
},
};
Then in my main.ts, the main process I have
(global as any).mynodegit = require('nodegit');
And then I use IPC to access nodegit within my renderer process. Note that the #ts-ignore is required to suppress error messages from typescript.
import { remote } from "electron";
// #ts-ignore
import * as Git from "#types/nodegit";
// #ts-ignore
const Git = remote.getGlobal('mynodegit');
Here is the boilerplate that helped me with this https://github.com/newblord/electron-react-webpack-nodegit-boilerplate

How to import Typescript file in Javascript file and interpret its contents before use?

I am writing a Node app with Typescript but my Cucumber test is in Javascript. My question: If I have a Typescript file:
import { Request, Response } from "express";
import checkCredentials from "./components/member/check-member-credentials";
import findMemberByEmail from "./components/member/find-member-by-email";
export default async (req: Request, res: Response) => {
const memberByEmail = await findMemberByEmail(req.body.password);
if (memberByEmail.error) {
return res.status(401).json({ message: "not found" });
}
const isMatch = await checkCredentials(
memberByEmail.member.password,
req.body.password,
);
if (isMatch) {
return res.status(200).json({ message: "logged in" });
}
return res.status(401).json({ message: "not auth" });
};
And I am trying to import it in the context file of Cucumber test:
require('../../../../src/controllers/login.ts');
I get the typical js error:
import { Request, Response } from "express";
^
SyntaxError: Unexpected token {
I tried to use a library typescript-require and require it before my import (as in its docs):
require('typescript-require');
const login = require("../../../../src/controllers/login.ts");
But I'm still getting error:
> NODE_ENV=development ./node_modules/.bin/cucumber-js test
src/controllers/components/member/check-member-credentials.ts(1,25): error TS2307: Cannot find module 'bcryptjs'.
src/controllers/components/member/check-member-credentials.ts(4,3): error TS2304: Cannot find name 'Promise'.
src/controllers/components/member/find-member-by-email.ts(1,16): error TS2307: Cannot find module '../../../db/models/index.js'.
src/controllers/components/member/find-member-by-email.ts(4,2): error TS2304: Cannot find name 'Promise'.
src/controllers/login-test.ts(1,35): error TS2307: Cannot find module 'express'.
src/controllers/login-test.ts(5,16): error TS1057: An async function or method must have a valid awaitable return type.
src/controllers/login-test.ts(11,25): error TS2346: Supplied parameters do not match any signature of call target.
src/controllers/login-test.ts(13,22): error TS1009: Trailing comma not allowed.
Fatal Error. Unable to compile TypeScript file. Exiting.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-basic-fit-v2#1.0.0 e2etest: `NODE_ENV=development ./node_modules/.bin/cucumber-js test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-basic-fit-v2#1.0.0 e2etest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ali.atrash/.npm/_logs/2019-07-08T14_53_57_742Z-debug.log
Any other solution?

Webpack - NodeJS - Module not found: Error: Can't resolve 'fs'

I am getting following error, when build nodejs project with webpack.
ERROR in ./node_modules/mime/mime.js
Module not found: Error: Can't resolve 'fs' in 'C:\Sample\node-ts-sample\node_modules\mime'
# ./node_modules/mime/mime.js 2:9-22
# ./node_modules/send/index.js
# ./node_modules/express/lib/response.js
# ./node_modules/express/lib/express.js
# ./node_modules/express/index.js
# ./src/server.ts
# ./src/index.ts
It was a node application. Added a following node in webpack config solved my issue
target:'node',
I refereed the article at https://jlongster.com/Backend-Apps-with-Webpack--Part-I
Simply add this to your webpack config file:
const webpackConfig = {
target: 'node'
};
module.exports = webpackConfig;

SlimScroll Error: Module build failed at ng2-slimscroll/index.ts

I have followed below steps Source from https://github.com/jkuri/ng2-slimscroll
Installation
npm install ng2-slimscroll
Imported module like
import { SlimScrollModule } from 'ng2-slimscroll';
imports: [ ....................,
SlimScrollModule,
......................]
facing Error in nodemodules/ng2-slimscroll/index.ts like
ERROR in ./~/ng2-slimscroll/index.ts
Module build failed: Error
at new FatalError (E:\ReconWorkspace\AgreeGateway\node_modules\tslint\lib\error.js:40:23)
at Function.findConfiguration (E:\ReconWorkspace\AgreeGateway\node_modules\tslint\lib\configurat
ion.js:47:15)
at resolveOptions (E:\ReconWorkspace\AgreeGateway\node_modules\tslint-loader\index.js:35:64)
at Object.module.exports (E:\ReconWorkspace\AgreeGateway\node_modules\tslint-loader\index.js:124
:17)
# ./src/main/webapp/app/test/test.module.ts 21:23-48
# ./src/main/webapp/app/app.module.ts
# ./src/main/webapp/app/app.main.ts
# multi (webpack)-dev-server/client?http://localhost:9060 webpack/hot/dev-server ./src/main/webapp/
app/app.main

Resources