Meteorjs with ta-lib npm module (server side) - node.js

I would like to use npm talib module within a meteorjs application.I followed the instruction here and I added this to the packages.json file:
{
"talib" : "0.6.0"
}
After running meteor the module talib.node is there in the node_modules/talib/build/Release/ folder.
Then I wrote the following:
if (Meteor.isServer) {
var Talib = Meteor.npmRequire('talib');
var talib = new Talib();
}
The Talib object is created and can be logged, like this:
{ version: '0.6.0',
functions:
[ { name: 'ADD',
group: 'Math Operators',
...
}
],
functionUnstIds:
{ TA_FUNC_UNST_ADX: 0,
TA_FUNC_UNST_ADXR: 1,
...
}
}
The line var talib = new Talib() gives instead this error:
TypeError: object is not a function
What I am doing wrong?

Related

How to connect lambda to CloudFront? AWS CDK JS

Code:
rootOriginFunc = new cloudfront.experimental.EdgeFunction(stack, 'RootOriginFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'origin.handler',
code: lambda.Code.fromAsset("./lib/lambdas"),
});
const lambdaFunctionAssociations = [
{
functionVersion: rootOriginFunc.currentVersion,
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
}
];
.....
....
{
pathPattern: pathPattern,
allowedMethods: cloudfront.CloudFrontAllowedMethods.ALL,
forwardedValues: {
queryString: true,
headers: ["Authorization"],
},
defaultTtl,
maxTtl,
minTtl,
isDefaultBehavior,
lambdaFunctionAssociations,
};
Error:
Users/denis/Documents/projects/ok/ok-app/cdk/node_modules/#aws-cdk/aws-cloudfront/lib/web-distribution.ts:601
if (a.lambdaFunction.role && a.lambdaFunction.role instanceof iam.Role && a.lambdaFunction.role.assumeRolePolicy) {
^
TypeError: Cannot read property 'role' of undefined
at CloudFrontWebDistribution.toBehavior (/Users/denis/Documents/projects/ok/ok-app/cdk/node_modules/#aws-cdk/aws-cloudfront/lib/web-distribution.ts:601:30)
at new CloudFrontWebDistribution (/Users/denis/Documents/projects/ok/ok-app/cdk/node_modules/#aws-cdk/aws-cloudfront/lib/web-distribution.ts:478:78)
at new CdkStack (/Users/denis/Documents/projects/ok/ok-app/cdk/lib/cdk-stack.ts:68:26)
at Object.<anonymous> (/Users/denis/Documents/projects/ok/ok-app/cdk/bin/cdk.ts:7:1)
The Question
According to documentation: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-cloudfront-readme.html#lambdaedge no role needs to be provided.
How to provide the required role?
Environment
CDK CLI Version: 1.116.0
Module Version: 1.116.0
Node.js Version: v15.3.0
OS: MacOS
Language (Version): Typescript 3.9.7
LambdaFunctionAssociations should take in: lambdaFunction
{
lambdaFunction: IVersion
eventType: LambdaEdgeEventType
}

setup webpack config in nextJS (next.config.js)

I'm working with NextJS and using react-data-export plugin to generate xls files.
in the description it says :
This library uses file-saver and xlsx and using
json-loader will do the magic for you.
///webpack.config.js
vendor: [
.....
'xlsx',
'file-saver'
],
.....
node: {fs: 'empty'},
externals: [
{'./cptable': 'var cptable'},
{'./jszip': 'jszip'}
]
but I have no idea how to implement it and got error like this :
The static directory has been deprecated in favor of the public directory. https://err.sh/vercel/next.js/static-dir-deprecated
Defining routes from exportPathMap
event - compiled successfully
> Ready on http://localhost:80 or http://localhost
> Ready on https://localhost:443 or https://localhost
event - build page: /menu_accounting/ReportGross
wait - compiling...
error - ./node_modules/react-export-excel/node_modules/xlsx/xlsx.js
Module not found: Can't resolve 'fs' in '/home/ahmadb/repos/lorry-erp/node_modules/react-export-excel/node_modules/xlsx'
Could not find files for /menu_accounting/ReportGross in .next/build-manifest.json
I had the same problem, the solution for me was this:
Install this packages (if you installed, ignored this)
npm install file-saver --save
npm install xlsx
npm install --save-dev json-loader
Add this to your nextjs.config.js
const path = require('path')
module.exports = {
...
//Add this lines
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.node = {
fs: 'empty'
}
}
return config
}
}

Error when trying to use CanvasJS via RequireJS

I'm trying to use CanvasJS inside my project. I'm using RequireJS to manage the modules, and have this in the main script:
define(['domReady',"canvasjs","common-functions"], function(domReady,CanvasJS) {
domReady(function () {
window.CanvasJS = CanvasJS;
init_page_select();
});
});
This is what I have in my requireJS config file for the path:
"paths": {
// other stuff here
"canvasjs": "node_modules/canvasjs/dist/canvasjs.min"
},
I can see the canvasjs.min.js file being grabbed fine - but then I get this weird error:
ReferenceError: intToHexColorString is not defined[Learn More] canvasjs.min.js:7:7042
[33]</n.prototype.render https://www.test.org/2018/js/lib/node_modules/canvasjs/dist/canvasjs.min.js:7:7042
[28]</n.prototype.render https://www.test.org/2018/js/lib/node_modules/canvasjs/dist/canvasjs.min.js:5:14150
n/this.render https://www.test.org/2018/js/lib/node_modules/canvasjs/dist/canvasjs.min.js:8:17771
init_page_select https://www.test.org/2018/js/lib/spot_view_stats.js:83:2
<anonymous> https://www.test.org/2018/js/lib/spot_view_stats.js:4:3
domReady https://www.test.org/2018/js/lib/domready.js:105:13
<anonymous> https://www.test.org/2018/js/lib/spot_view_stats.js:2:2
execCb https://www.test.org/2018/js/lib/require.js:5:12859
check https://www.test.org/2018/js/lib/require.js:5:6575
enable/</< https://www.test.org/2018/js/lib/require.js:5:9031
bind/< https://www.test.org/2018/js/lib/require.js:5:812
emit/< https://www.test.org/2018/js/lib/require.js:5:9497
each https://www.test.org/2018/js/lib/require.js:5:289
emit https://www.test.org/2018/js/lib/require.js:5:9465
check https://www.test.org/2018/js/lib/require.js:5:7169
enable/</< https://www.test.org/2018/js/lib/require.js:5:9031
bind/< https://www.test.org/2018/js/lib/require.js:5:812
emit/< https://www.test.org/2018/js/lib/require.js:5:9497
each https://www.test.org/2018/js/lib/require.js:5:289
emit https://www.test.org/2018/js/lib/require.js:5:9465
check https://www.test.org/2018/js/lib/require.js:5:7169
enable https://www.test.org/2018/js/lib/require.js:5:9358
init https://www.test.org/2018/js/lib/require.js:5:5716
h https://www.test.org/2018/js/lib/require.js:5:4287
completeLoad https://www.test.org/2018/js/lib/require.js:5:12090
onScriptLoad https://www.test.org/2018/js/lib/require.js:5:13014
I'm invoking it with:
var chart = new CanvasJS.Chart("thegraph",
{
title:{
text: impressionText
},
theme: "theme2",
axisX: {
valueFormatString: "MMM-DD-YYYY",
labelAngle: -50
},
axisY:{
valueFormatString: "#0",
title: impressionText
},
data: [
{
type: "line",
showInLegend: true,
legendText: legendText,
dataPoints: dataPoints
}
]
});
chart.render();
Interestingly, if I tell it to load canvasjs.js instead of canvasjs.min.js, I get another error:
ReferenceError: intToHexColorString is not defined[Learn More]
OK so the problem seemed to be my version. For some reason "npm install canvasjs" was installing 1.8.1, but 2.2 was out. As per their request, I updated it to 2.2 and it sorted the problem. It seems weird npm is running such an outdated version though

Slack Integraton with Laravel Issues

I am trying to install slack node library, but not able to do it successfully.
I installed this library successfully on laravel 5.4 using node js. And my gulpfile is upgraded from 5.3 to 5.4 and attached below.
npm install #slack/client --save (Installation is fine but gukp is causing issue)
But when i run gulp command on shell i am getting following error:-
After adding adding this line in app.js:-
var RtmClient = require('#slack/client').RtmClient;
gulpfile.js (manually eddited)
const elixir = require('laravel-elixir');
const path = require('path');
const debug = require('gulp-debug');
const moment = require('moment');// in my gulp file
require('laravel-elixir-webpack-official');
require('laravel-elixir-vue-2');
elixir(function(mix) {
// Elixir.webpack.config.module.loaders = [];
Elixir.webpack.mergeConfig({
resolveLoader: {
root: path.join(__dirname, 'node_modules'),
},
module: {
loaders: [
{
test: /\.css$/,
loader: 'style!css'
}
]
}
});
mix.sass('app.scss')
.webpack('app.js')
.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/','public/fonts/bootstrap')
});
Error on Gulp Command
user1#console:/opt/lampp/htdocs/dev$ gulp
[15:40:27] Using gulpfile /opt/lampp/htdocs/dev/gulpfile.js
[15:40:27] Starting 'all'...
[15:40:27] Starting 'sass'...
[15:40:28] Finished 'sass' after 1.08 s
[15:40:28] Starting 'webpack'...
{ [Error: ./~/winston/package.json
Module parse failed: /opt/lampp/htdocs/dev/node_modules/winston/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| {
# ./~/winston/lib/winston.js 14:18-44
# ./~/#slack/client/lib/helpers.js
# ./~/#slack/client/lib/clients/client.js
# ./~/#slack/client/lib/clients/web/client.js
# ./~/#slack/client/index.js
# ./resources/assets/js/app.js./~/winston/lib/winston/common.js
Module not found: Error: Can't resolve 'fs' in '/opt/lampp/htdocs/dev/node_modules/winston/lib/winston'
resolve 'fs' in '/opt/lampp/htdocs/dev/node_modules/winston/lib/winston'
Parsed request is a module
using description file: /opt/lampp/htdocs/dev/node_modules/winston/package.json (relative path: ./lib/winston)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /opt/lampp/htdocs/dev/node_modules/winston/package.json (relative path: ./lib/winston)
resolve as module
/opt/lampp/htdocs/dev/node_modules/node_modules doesn't exist or is not a directory
Thanks in advance

Fatal error when scraping dynamic page content with x-ray and x-ray-phantom

I am getting this error in the command line when I run app.js on node:
FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope
Abort trap: 6
This is what am app.js looks like:
var phantom = require('x-ray-phantom');
var Xray = require('x-ray');
var fs = require('fs');
x = new Xray().driver(phantom());;
x('http://www.bbc.co.uk/news', '.most-popular__list panel-read li', [{
content: ''
}])(function (err, results) {
fs.writeFile('results.json', JSON.stringify(results, null, '\t'));
})
My package.json
{
...
"dependencies": {
"phantomjs": "^1.9.19",
"x-ray": "^2.0.2",
"x-ray-phantom": "^1.0.1"
}
...
}
My node version is v5.3.0, Npm version is 3.3.12, Phantomjs version is 1.9.8. I am on a Mac El Capitan 10.11.1
Check if this works:
x = new Xray().driver(phantom({
dnodeOpts: {
weak: false
}
}));
I use phantom instead of x-ray-phantom and I encountered the same issue. It appears that the module node-weak is broken (https://github.com/TooTallNate/node-weak/issues/65), and bypassing this module as this link suggests has solved my case.

Resources