AWS IoT Javascript SDK can not create client - javascript

I'm using Vue.js, TypeScript, and the aws-iot-device-sdk package and like to subscribe to a IoT topic. This is how I create a new client:
import AwsIot from 'aws-iot-device-sdk';
import { config } from 'aws-sdk';
client = new AwsIot.device({
region: 'foo',
host: 'foo',
clientId: 'foo',
protocol: 'wss',
accessKeyId: config.credentials.accessKeyId,
secretKey: config.credentials.secretAccessKey,
sessionToken: config.credentials.sessionToken
});
One seconds later I get this console error:
Uncaught TypeError: Cannot read property 'read' of undefined
at nReadingNextTick (_stream_readable.js)
Uncaught TypeError: Cannot read property 'length' of undefined
at onwriteDrain (_stream_writable.js)
at afterWrite (_stream_writable.js)
Uncaught TypeError: Cannot read property 'length' of undefined
at onwriteDrain (_stream_writable.js)
at afterWrite (_stream_writable.js)
Uncaught TypeError: Cannot read property '_readableState' of undefined
at emitReadable_ (_stream_readable.js)
Uncaught TypeError: Cannot read property 'reading' of undefined
at maybeReadMore_ (_stream_readable.js)

node-libs-browser's implementation of process.nextTick does not accept callback arguments. Just override it inside your main.ts!
process.nextTick = function(callback) {
const args = [...arguments];
args.shift();
setTimeout(() => callback.apply(null, args));
}
UPDATE:
It's fixed in v2.2.1: Commit

Related

MOJavaScriptException: TypeError: undefined is not an object (evaluating 'exports.Headers = global.Headers')

I've encounted an error of MOJavaScriptException: TypeError: undefined is not an object (evaluating 'exports.Headers = global.Headers') while trying to import discord-rpc to my Sketch Plugin project, couldn't Googled anything related online.
Full code
import sketch from 'sketch'
const { Client } = require("discord-rpc");
export default function() {
}
Full Error Message
MOJavaScriptException: TypeError: undefined is not an object (evaluating 'exports.Headers = global.Headers')
./node_modules/node-fetch/browser.js browser.js:23:0
__webpack_require__ bootstrap:19:0
client.js:5:22
./node_modules/discord-rpc/src/client.js __my-command.js:1047:34
__webpack_require__ bootstrap:19:0
./node_modules/discord-rpc/src/index.js index.js:6:18
__webpack_require__ bootstrap:19:0
./src/my-command.js my-command.js:2:27
__webpack_require__ bootstrap:19:0
bootstrap:83:0
I've tried to move the const { Client } = require("discord-rpc"); inside of export default function() {}, but no luck. changed my code to const discord = require("discord-rpc") is also tried.

TypeError: Cannot read properties of undefined (reading 'session')

I'm trying to set up some cookies for my electron application but when the code on the function below executes, this error comes out TypeError: Cannot read properties of undefined (reading 'session').
const { session } = require("electron")
function updatePatient(id) {
session.defaultSession.cookies.set({url: './', name: 'patientId', value: id})
ipcRenderer.send('updatePatientWindow')
}
updatePatient(id)
I also tried to use
const { electron } = require('electron')
electron.session.defaultSession.cookies.set({url: './', name: 'patientId', value: id})
but that doesn't work either
Edit:
Seems like session works only on the main process. A workaround is to use ipcRenderer there to set and read cookies.

Sync firebase (vuexfire) without errors and warnings

I have a firestore binding in my vuex store, on which one frontend element depends. Here is some example code:
Vue Template:
<v-list-item
v-if="dependantGetter"
#click="doSomething()">
<v-list-item-title>Do something</v-list-item-title>
</v-list-item>
Vue Script:
computed: {
...mapGetters(["dependantGetter"]),
}
Vuex Store:
const state = {
settings : [],
}
const getters = {
dependantGetter: ({ settings }) => {
let check = settings.filter(setting => setting.id === 'idName')
return check[0].startSync
}
}
But the problem I have is, that the browser throws multiple errors until the binding becomes true or false:
[Vue warn]: Error in render: "TypeError: Cannot read property 'startSync' of undefined"
TypeError: Cannot read property 'startSync' of undefined
[Vue warn]: Error in render: "TypeError: Cannot read property 'startSync' of undefined"
TypeError: Cannot read property 'startSync' of undefined
[Vue warn]: Error in render: "TypeError: Cannot read property 'startSync' of undefined"
TypeError: Cannot read property 'startSync' of undefined
My solution so far is to return the getter like this from inside vuex, but this really doesn't look right to me
return check[0] == undefined ? false : check[0].startSync
Or is this the right way to return things, when working with firebase and vuexfire?

Cloud function fails after changing Runtime to Node.js 10

I am trying to take firebase backup through a cloud function. The function was running completely fine when I was using Runtime: Node.js 8. However, since it is going to be deprecated soon, I now have to use Node.js 10. My fcloud function now fails with the below error:
Error: function execution failed. Details:
Cannot read property 'charCodeAt' of undefined
Detailed error log:
2020-05-27 11:01:21.820 IST
firestore_export
8kxlp9s867dy
TypeError: Cannot read property 'charCodeAt' of undefined at peg$parsetemplate (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:304:17) at Object.peg$parse [as parse] (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:633:18) at new PathTemplate (/workspace/node_modules/google-gax/build/src/pathTemplate.js:55:54) at segments.forEach.segment (/workspace/node_modules/google-gax/build/src/pathTemplate.js:120:29) at Array.forEach (<anonymous>) at PathTemplate.render (/workspace/node_modules/google-gax/build/src/pathTemplate.js:114:23) at FirestoreAdminClient.databasePath (/workspace/node_modules/#google-cloud/firestore/build/src/v1/firestore_admin_client.js:904:57) at exports.scheduledFirestoreBackup (/workspace/index.js:6:31) at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/#google-cloud/functions-framework/build/src/invoker.js:330:28) at process._tickCallback (internal/process/next_tick.js:68:7)
Expand all | Collapse all
{
insertId: "000000-f688386c-8f2b-4146-aaf7-1fe67c656fa2"
labels: {…}
logName: "projects/firestore-249705/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2020-05-27T05:31:31.171084310Z"
resource: {…}
severity: "ERROR"
textPayload: "TypeError: Cannot read property 'charCodeAt' of undefined
at peg$parsetemplate (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:304:17)
at Object.peg$parse [as parse] (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:633:18)
at new PathTemplate (/workspace/node_modules/google-gax/build/src/pathTemplate.js:55:54)
at segments.forEach.segment (/workspace/node_modules/google-gax/build/src/pathTemplate.js:120:29)
at Array.forEach (<anonymous>)
at PathTemplate.render (/workspace/node_modules/google-gax/build/src/pathTemplate.js:114:23)
at FirestoreAdminClient.databasePath (/workspace/node_modules/#google-cloud/firestore/build/src/v1/firestore_admin_client.js:904:57)
at exports.scheduledFirestoreBackup (/workspace/index.js:6:31)
at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/#google-cloud/functions-framework/build/src/invoker.js:330:28)
at process._tickCallback (internal/process/next_tick.js:68:7)"
timestamp: "2020-05-27T05:31:21.820Z"
trace: "projects/firestore-249705/traces/74e27700d135763bc4e7892ebb1a2333"
}
My index.js is as below:
const firestore = require('#google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
// Replace BUCKET_NAME
const bucket = 'gs://gcp_firestore_ae2/firestore_export'
exports.scheduledFirestoreBackup = (event, context) => {
const databaseName = client.databasePath(
process.env.GCLOUD_PROJECT,
'(default)'
);
return client
.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
// Leave collectionIds empty to export all collections
// or define a list of collection IDs:
// collectionIds: ['users', 'posts']
collectionIds: ['most_valuable_items','nric_img','pay_slip','pic_of_ofc_entrance'],
})
.then(responses => {
const response = responses[0];
console.log(`Operation Name: ${response['name']}`);
return response;
})
.catch(err => {
console.error(err);
});
};
I had the same issue. I fixed it by changing:
process.env.GCLOUD_PROJECT
to my actual Project ID (e.g. "my_app_37274")
I had the same issue, It seems like in previous versions we don't need to GCLOUD_PROJECT in environment variable i.e it automatically detects it, but from node 10 onwards we need to pass this explicitly.
That's how I resolved it.
So instead of hardcoding it, try passing GCLOUD_PROJECT in cloud functions environment variables.
Note: GCLOUD_PROJECT is project id, not the project name.

Error "TypeError: Cannot read property 'indexOf' of undefined" when using ipfs-api

I was performing development using ipfs - api, I encountered the following error, add of image file to ipfs node does not work well.
Looking at the details of the error, it seems that protocol is treated as undefined among if (protocol.indexOf ('https') === 0) { in request.js.
This is the error description
Uncaught (in promise) TypeError: Cannot read property 'indexOf' of undefined
at webpackJsonp../node_modules/ipfs-api/src/utils/request.js.module.exports (request.js:7)
at requestAPI (send-request.js:165)
at send (send-request.js:196)
at send-files-stream.js:99
at Function.promisify (add.js:41)
at index.js:32
at Object.add (add.js:60)
at VueComponent._callee$ (HaikuCompose.vue?0664:118)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:296)
This is the code I wrote
import IPFS from "ipfs-api"
const ipfsConf = { host: process.env.IPFSHOST, port: process.env.IPFSPORT, protocol: process.env.IPFSPROTCOL }
const ipfs = new IPFS(ipfsConf)
export default {
name: 'ipfstest',
data() {
return {
file:null,
buffer:null,
ipfsHash:null,
}
},
methods: {
async addipfs() {
await ipfs.add(this.buffer, (err, ipfsHash) => {
console.log(err,ipfsHash);
this.ipfsHash = ipfsHash[0].hash;
})
},
From the module sources, indexOf on line 7 of the request.js file is used on the variable storing the protocol, which is undefined in your case.
And from your code, I think I can safely assume that your environment variable process.env.IPFSPROTCOL is undefined.
TL:DR : I think you wanted to write IPFSPROTOCOL instead of IPFSPROTCOL

Categories