read excl file to nestjs using excljs - javascript

I am trying to process excl file into nestjs app
import ExcelJS from 'exceljs';
.
.
.
async import(file) {
const workBook = new ExcelJS.Workbook();
const data = await workBook.xlsx.load(file);
}
and I got that error
TypeError: Cannot read properties of undefined (reading 'Workbook')

I made a mistake in importing, it should be like
import * as ExcelJS from "exceljs";

Related

Web push import from another file

I'm having a little problem, I have Web Push settings in one file called WebPush.ts and I want to import it to another file. but I'm getting an error.
WebPush.ts
import webpush from 'web-push'
export const WebPush = webpush.setVapidDetails(
`mailto:${process.env.ADMIN_EMAIL}`,
process.env.PUBLIC_VAPID_KEY!,
process.env.PRIVATE_VAPID_KEY!
)
and in another file I am importing it.
import { WebPush } from '../../Services/WebPush'
async somefunction(){
await WebPush.sendNotification(pushSubscripton, payload)
}
I'm getting this error:
Property 'sendNotification' does not exist on type 'void'.ts(2339)
But when I do settings in this file where I want to import this I Don't get error. How can I fix this?

Node.js - Unable to load from module

Using a JS sdk of Icon a blockchain. Trying to using the SDK API calls and I'm having issues import or require
When I use Import an error is thrown SyntaxError: Cannot use import statement outside a module
When I use require an error is thrown ReferenceError: HttpProvider is not defined
Below is the link to Icon Icx Github
Icon GitHub
const IconService = require('icon-sdk-js');
//import IconService from 'icon-sdk-js';
const provider = new HttpProvider('https://bicon.net.solidwallet.io/api/v3');
const iconService = new IconService(provider);
const totalSupply = iconService.getTotalSupply().execute();
console.log(totalSupply);
In NodeJS you use require to "import" node modules and dependencies to your project
const IconService = require('icon-sdk-js');
Regarding this line const provider = new HttpProvider('https://bicon.net.solidwallet.io/api/v3');
Where are you importing HttpProvider from? HttpProvider is not built in Javascript library.
If it is a node module, you have to do something similar
const HttpProvider = require('HttpProvider'); (in your question you don't specify what HttpProvider is)
I think you might use IconService.HttpProvider('the url'); to use the constructor

How to read a local JSON file in React JS + Typescript app and access the data?

I am trying to read a local JSON file in ReactJS + Typescript office add-in app.
I created a typings.d.ts in the src folder and added the following.
declare module "*.json" {
const value: any;
export default value;
}
declare module "json!*" {
let json: any;
export default json;
}
I imported the file in my component file like this
import * as data from './../../mock-data/pre-output.json';
The JSON file has data similar to the following
{
"result": {
"ruleFeedback": [
{
"key": "Deal Size",
"version": 1,
"category": "Segmentation"
}
]}
}
And I tried to access this data like the following in my function.
const newData = data.results.ruleFeedback.map(item =>
[item.key, item.version,item.category, item.selectedValue]);
But I am getting an error TypeError: undefined is not an object (evaluating 'data.results.ruleFeedback')
I even tried the import like this
import data = require('./../../mock-data/pre-output.json');
But I am getting the same error.
Any idea where I am going wrong?
I am very new to this JS technology stack.
I had a problem loading JSON data once. For me, the solution was to put the json file into the public folder of my app (generated with create-react-app)

How to integrate skylink in react project?

I am using Skylink for video calling and I want to use in a react project. I know how to use it with Vanilla JavaScript as their demo project is at codepen
But when I try to use it with react I am getting some errors. Here is how I tried:
Installed the package from npm using Yarn.
Imported the package import SkyLink from 'skylinkjs'
Then called the function constructor const skylink = new SkyLink();
But I get the following error:
Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_skylinkjs___default.a is not a constructor
If I try to import like this:
import {SkyLink} from 'skylinkjs';
const skylink = new SkyLink();
then the error is
Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_skylinkjs__.SkyLink is not a constructor
and If I try to import all from the module and then call the function costructor:
import * as SkyLink from 'skylinkjs';
const skylink = new SkyLink();
the error will be this Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_skylinkjs__ is not a constructor
Can you please tell me what am I doing wrong?
You have a typo. Either of the following would work.
import { Skylink } from 'skylinkjs';
const skylink = new Skylink();
or
import skylinkjs from 'skylinkjs';
const skylink = new skylinkjs.Skylink();

Cannot read property 'ref' of undefined

I'm building a simple web app with Vue + Firebase + Vuefire and I get "Uncaught TypeError: Cannot read property 'ref' of undefined" when I try to use my Firebase db variable inside a component.
In main.js
Vue.use(VueFire)
const firebaseApp = Firebase.initializeApp({ //setting })
// Export the database for components to use.
export const db = firebaseApp.database()
And in my component
// in Recipes.vue
import {db} from '../main.js'
export default {
recipe: {
source: db.ref('recipes')
// Console says: "Uncaught TypeError: Cannot read property 'ref' of undefined"
}
}
I followed the steps in this tutorial https://alligator.io/vuejs/vuefire-firebase/
This code db.ref('recipes') works if used inside main.js, but it never works once I import it inside my component.
The problem was my Firebase code (including db variable) was inside main.js but it needed to be in it's own component. I created a firebase.js file :
import Firebase from 'firebase'
const firebaseApp = Firebase.initializeApp({
# configuration
})
// Export the database for components to use.
export const db = firebaseApp.database()
Then in my component I simply imported my database variable :
import {db} from '../firebase'
Why didn't it work inside main.js? I'm not sure, maybe someone more knowledgeable can answer that.
.ref is a firebase function, you need to import it. try
import Firebase from 'firebase'
or
import * from 'firebase'

Categories