Clarifai api referenceerror : process is not defined - javascript

I get such an error on npm start on clarifai api
[1]: https://i.stack.imgur.com/pHRNz.png
Open bootstrap:27:
// Execute the module function
try {
var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ };
__webpack_require__.i.forEach(function(handler) { handler(execOptions); });
module = execOptions.module;
execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
} catch(e) {
module.error = e;
throw e;
}
// Flag the module as loaded
module.loaded = true;
// Return the exports of the module
return module.exports;
}
and my App.js details;
const app = new Clarifai.App({
apiKey: '****',
})
///
onButtonSubmit = () => {
console.log('click')
app.models
.predict(
'45fb9a671625463fa646c3523a3087d5',
'https://samples.clarifai.com/metro-north.jpg'
)
.then(
function (response) {
console.log(response)
},
function (err) {
//
}
)
}
I am getting this error before render in console.log. what would be the reason?
Happy coding day! :)

As stated in the documentation you need to use Broserify. You are missing NodeJS globals. Please let us know if this does not work for you as this library is unfortunately not under active maintenance currently.

Related

Uncaught Error: Mismatched anonymous define() module: function() {return uuid;}

I have installed pinata SDK using
npm install --save #pinata/sdk
I’m implementing the code to add files to IPFS using pinata
const pinataSDK= require('#pinata/sdk');
const pinata = pinataSDK('812f8a2d416d9be9afea', '668516ac85834685ed785bcaec839f5ad1aeca099788cd8aa814ccdbad77d1bb');
console.log("entered");
pinata.testAuthentication().then((result) => {
//handle successful authentication here
console.log(result);
}).catch((err) => {
//handle error here
console.log(err);
});
const fs = require('fs');
const readableStreamForFile = fs.createReadStream('./naruto6.jpeg');
const options = {
pinataMetadata: {
name: MyCustomName,
keyvalues: {
customKey: 'customValue',
customKey2: 'customValue2'
}
},
pinataOptions: {
cidVersion: 0
}
};
pinata.pinFileToIPFS(readableStreamForFile, options).then((result) => {
//handle results here
console.log(result);
}).catch((err) => {
//handle error here
console.log(err);
});
I’m facing the following error.
https://requirejs.org/docs/errors.html#notloaded
https://requirejs.org/docs/errors.html#mismatch
I have installed the require.js node module. I could not understand the error properly. I'm new to js. Please help me out.

Eager loading with Feathers JS 4 and Objection JS - Cannot read property 'get' of undefined

I am using feathers js 4 with objection ORM and trying to create a service that returns objection js model data that includes an eager loaded BleongsToOneRelation but I keep getting the response:
Cannot read property 'get' of undefined
I have used the Feathers CLI to generate my service (and model) and then modified to add a relationship as follows:
devices.model.js
const { Model } = require('objection');
class devices extends Model {
static get tableName() {
return 'devices';
}
static get jsonSchema() {
return {
type: 'object',
required: ['macAddress'],
properties: {
macAddress: { type: 'string' },
circuitId: { type: 'integer' },
}
};
}
static get relationMappings() {
const Circuit = require('./circuits.model')();
const DeviceType = require('./device-types.model')();
return {
circuit: {
relation: Model.BelongsToOneRelation,
modelClass: Circuit,
join: {
from: 'devices.circuitId',
to: 'circuits.id'
}
}
};
}
$beforeInsert() {
this.createdAt = this.updatedAt = new Date().toISOString();
}
$beforeUpdate() {
this.updatedAt = new Date().toISOString();
}
}
module.exports = function (app) {
const db = app.get('knex');
db.schema.hasTable('devices').then(exists => {
if (!exists) {
db.schema.createTable('devices', table => {
table.increments('id');
table.string('macAddress');
table.integer('circuitId');
table.timestamp('createdAt');
table.timestamp('updatedAt');
})
.then(() => console.log('Created devices table')) // eslint-disable-line no-console
.catch(e => console.error('Error creating devices table', e)); // eslint-disable-line no-console
}
})
.catch(e => console.error('Error creating devices table', e)); // eslint-disable-line no-console
return devices;
};
device.class.js
const { Devices } = require('./devices.class');
const createModel = require('../../models/devices.model');
const hooks = require('./devices.hooks');
module.exports = function (app) {
const options = {
Model: createModel(app),
paginate: app.get('paginate'),
whitelist: ['$eager', '$joinRelation', '$modifyEager'],
allowedEager: ['circuit']
};
// Initialize our service with any options it requires
app.use('/devices', new Devices(options, app));
// Get our initialized service so that we can register hooks
const service = app.service('devices');
service.hooks(hooks);
};
Then I am calling the /devices GET request using http://localhost:3030/devices?$eager=circuit
and the result is:
{
"name": "GeneralError",
"message": "Cannot read property 'get' of undefined",
"code": 500,
"className": "general-error",
"data": {},
"errors": {}
}
Have tried adding a custom find() method to devices.class.js but this doesn't seem to help.
I've searched through similar questions here and read through the feathers-objection docs but just can't see what I'm missing. Any assistance would be greatly appreciated.
Sounds like your app variable is undefined. Debugger could help you a lot if you add a breakpoint and check call stack to see why... Maybe you are not passing it everywhere correctly to your modules.
This is the code that throws your error:
https://runkit.com/embed/kipjj807i90l
It happens because in your relationMappings you are initializing models without the app argument which is expected. In the feathers-objection examples it is shown how to modify your models in order to use them in the relation mappings: you have to explicitly handle the missing app argument.
I know it's much later, but I just found the same problem.
The solution is to modify the feathers-objection models with the following, based on the Models section here
module.exports = function(app) {
if (app) {
const db = app.get('knex');
.... etc
}
return User;
};
module.exports = User;

Config param are undefined in error handler

I have a config file that just sets the process.env data to params.
It works fine and I can use it correctly everywhere but on my unexpected exceptions handler I can't use it... all the params from the config file are undefined.
my config file:
module.exports = {
env: process.env.NODE_ENV,
};
here is my uncaught exception catcher:
process.on('uncaughtException', (error) => {
errorManagement.handler.handleError(error);
if (!errorManagement.handler.isTrustedError(error)) process.exit(1);
});
and here is error handler, env is undefined, everywhere else env is defined
const {
env,
} = require('../../config');
const logger = require('../../libraries/logger');
const mailer = require('../../libraries/mailer');
function ErrorHandler() {
this.handleError = async (err) => {
console.log(env);
};
}
module.exports.handler = new ErrorHandler();
tree of my project folder:
EDIT:
I found the problem but I'm still not sure why it happened...
in my config.js file I did:
const errorManager = require('./components/errorManagement');
[
'DB_USER',
].forEach((name) => {
if (typeof process.env[name] === 'undefined') {
throw new errorManager.AppError('Environment var missing', 500, `Environment variable ${name} is missing`, true);
}
});
when I deleted the error manager and used express Error everything worked as expected

ReferenceError: process is not defined

I am running a k6 test and using env variables for some of the code. I keep getting this darn error though:
ReferenceError: process is not defined
I have tried using an alternate some people suggested in a similar issue using __ENV.yadda, but that did not work.
import http from "k6/http";
let formData = {
client_id: "LoadTesting",
grant_type: "blah_blah",
scope: "Scope",
};
const messageHeaders = {
'Content-Type': 'Client Type',
};
let user = null;
export function authorizeUser() {
formData.client_secret = process.env.REACT_APP_CLIENT_SECRET;
if (!user) {
let res = http.post(`https://localhost:44341/connect/token`, formData, { headers: messageHeaders });
if (res.status != 200) {
console.log('res: ', res.status);
throw new Error("couldn't load user");
}
user = JSON.parse(res.body).access_token;
return user;
}
}
I just want my env variables to work!
The environment variable in the k6 works different as for the Node.js try something as that:
https://k6.io/docs/using-k6/environment-variables
You can use the k6/x/dotenv extension library to do this. Please see: https://github.com/szkiba/xk6-dotenv for more information
At the start of your file:
import dotenv from "k6/x/dotenv";
const env = dotenv.parse(open('/path/to/your/.env'))
Then get your environment variables like so:
const yourEnvVar = env.YOUR_ENV_VAR

How to require module only if exist. React native

Example:
let tmp;
try {
tmp = require('module-name');
} catch(e) {
return;
}
I get error (react native Metro Bundler):
error: bundling failed: Error: Unable to resolve module `module-name` from ...
How to require "module-name" only if exist?
That's what works for me:
let myPackage;
const myPackageToRequire = 'my-package-to-require';
try {
myPackage = require.call(null, myPackageToRequire);
} catch (e) {}
The variable definition const myPackageToRequire = 'my-package-to-require'; is necessary here.
Hope I helped.
Loading optional dependencies via try-catch has been added in Metro 0.59, which in turn means that you should be able to use your original code in React Native 0.63 if you turn it on in metro.config.js:
module.exports = {
transformer: {
allowOptionalDependencies: true,
},
}
Use require.resolve which will return resolved file name.
function checkModuleAvailability (module) {
try {
require.resolve(module);
return true
} catch(e) {
console.log(`${module} not found`);
}
return false
}
const moduleAvailable = checkModuleAvailability(MODULE_NAME) // true or false

Categories

Resources