I have a index.js and the handler function is defined. But when I test I get the error index.handler is undefined or not exported. Any idea how to resolve this?
{
"errorType": "Runtime.HandlerNotFound",
"errorMessage": "index.handler is undefined or not exported",
"trace": [
"Runtime.HandlerNotFound: index.handler is undefined or not exported",
" at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)",
" at Object.<anonymous> (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:999:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
" at Module.load (internal/modules/cjs/loader.js:863:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
" at internal/main/run_main_module.js:17:47"
]
}
Function Logs
START RequestId: fa81b4c8-23f6-4f15-899b-dfc680ae9c57 Version: $LATEST
2021-10-29T08:47:21.477Z undefined ERROR Uncaught Exception {"errorType":"Runtime.HandlerNotFound","errorMessage":"index.handler is undefined or not exported","stack":["Runtime.HandlerNotFound: index.handler is undefined or not exported"," at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)"," at Object.<anonymous> (/var/runtime/index.js:43:30)"," at Module._compile (internal/modules/cjs/loader.js:999:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)"," at Module.load (internal/modules/cjs/loader.js:863:32)"," at Function.Module._load (internal/modules/cjs/loader.js:708:14)"," at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)"," at internal/main/run_main_module.js:17:47"]}
2021-10-29T08:47:22.789Z undefined ERROR Uncaught Exception {"errorType":"Runtime.HandlerNotFound","errorMessage":"index.handler is undefined or not exported","stack":["Runtime.HandlerNotFound: index.handler is undefined or not exported"," at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)"," at Object.<anonymous> (/var/runtime/index.js:43:30)"," at Module._compile (internal/modules/cjs/loader.js:999:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)"," at Module.load (internal/modules/cjs/loader.js:863:32)"," at Function.Module._load (internal/modules/cjs/loader.js:708:14)"," at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)"," at internal/main/run_main_module.js:17:47"]}
END RequestId: fa81b4c8-23f6-4f15-899b-dfc680ae9c57
REPORT RequestId: fa81b4c8-23f6-4f15-899b-dfc680ae9c57 Duration: 1463.33 ms Billed Duration: 1464 ms Memory Size: 128 MB Max Memory Used: 11 MB
Unknown application error occurred
Runtime.HandlerNotFound
Request ID
fa81b4c8-23f6-4f15-899b-dfc680ae9c57
Lambda functions do not yet support ES6 style (https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html)
You should use:
exports.handler = async function(event, context) {
}
Related
test codeļ¼
function throw_erorr(){
throw TypeError("test error")
}
try{
throw_erorr()
}catch(err){
console.log("==err:", err)
}
results:
PS E:\code\nodejs\star> node .\main.js
==err: TypeError: test error
at throw_erorr (E:\code\nodejs\star\main.js:12:11)
at Object. (E:\code\nodejs\star\main.js:16:5)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Why?Tanks!
In Node.js, I noticed that file operations were not always stable. I have the impression that fs gives up when the operations are not completely finished. Here is an example to illustrate:
"use strict";
Error.stackTraceLimit = Infinity;
const fs = require("fs");
const filename = "foo.txt";
for (let i = 0; ; i++) {
try {
fs.writeFileSync(filename, "bar");
fs.unlinkSync(filename);
}
catch (e) {
throw Object.assign(new Error(`Error at iteration ${i}!`), { cause: e });
}
}
After a certain number of iterations, I get an error :
Error: Error at iteration 12980!
at Object.<anonymous> (C:\test.js:15:4)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
cause: Error: EPERM: operation not permitted, open 'foo.txt'
at Object.openSync (fs.js:462:3)
at Object.writeFileSync (fs.js:1384:35)
at Object.<anonymous> (C:\test.js:10:6)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
errno: -4048,
syscall: 'open',
code: 'EPERM',
path: 'foo.txt'
}
}
Do you have the same observation?
How can we ensure that these operations are stable?
I am trying to declare a logger object, then have a child function write to the log that was declared in the parent using the context. However the context appears to be undefined inside the children, whether I use an arrow function or not.
Is it possible to pass the winston object to the child function implicitly ie without having to pass a winston object as a parameter?
Error log output:
this main context: {}
undefined
l1 err: TypeError: Cannot read properties of undefined (reading 'winston')
at l1 (MYPATH\cw_log_test_helper.ts:4:19)
at run (MYPATH\cw_log_contexts.ts:30:7)
at Object.<anonymous> (MYPATH\cw_log_contexts.ts:39:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module.m._compile (MYPATH\node_modules\ts-node\src\index.ts:1371:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (MYPATH\node_modules\ts-node\src\index.ts:1374:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
{ l1: [Function: l1], r1: [AsyncFunction: r1] }
r1 err: TypeError: Cannot read properties of undefined (reading 'error')
at r1 (MYPATH\cw_log_test_helper.ts:12:31)
at run (MYPATH\cw_log_contexts.ts:31:7)
at Object.<anonymous> (MYPATH\cw_log_contexts.ts:39:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module.m._compile (MYPATH\node_modules\ts-node\src\index.ts:1371:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (MYPATH\node_modules\ts-node\src\index.ts:1374:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
bye
main.ts
var winston=require('winston');
var WinstonCloudWatch=require('winston-cloudwatch');
import { l1, r1 } from './cw_log_test_helper';
const AWS = require('aws-sdk');
AWS.config.update({
region: 'us-east-1',
});
var run=()=>{
let sname=`mylambda`
var self=winston.add(new WinstonCloudWatch({
name:sname,
cloudWatchLogs: new AWS.CloudWatchLogs(),
logGroupName: 'winston-testing',
logStreamName: sname
}));
console.log(`this main context:`,this)
winston.error('first'); //<<<<<<<<<<<<<<<<<<WORKS
l1(`hello`) //<<<<<<<<<<<<<<<<FAILS
r1('hi') //<<<<<<<<<<<<<<<<FAILS
// flushes the logs and clears setInterval
var transport = self.transports.find((t) => t.name === sname)
transport.kthxbye(function() {
console.log('bye');
});
}
run()
cw_log_test_helper.ts:
export var l1=function(ltxt:string){
console.log(this)
try{
(this as any).winston.error(ltxt);
}catch(e){
console.log(`l1 err:`,e)
}
}
export var r1 = async (ltxt:string) => {
console.log(this)
try{
(this as any).winston.error(ltxt);
}catch(e){
console.log(`r1 err:`,e)
}
}
i am trying to make a simple React/Truffle project.
Truffle-config file:
module.exports = {
contracts_build_directory: "./src/contracts",
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*",
}
},
mocha: {
},
compilers: {
solc: {
}
}
};
The migrations work and json files get created. However, when i run truffle test
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
TypeError: contracts_build_directory is not a function
at Object.<anonymous> (C:\Users\disst\Desktop\github\smart-contract\test\marketTest.js:7:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Users\disst\AppData\Roaming\npm\node_modules\truffle\node_modules\mocha\lib\mocha.js:390:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\disst\AppData\Roaming\npm\node_modules\truffle\node_modules\mocha\lib\mocha.js:387:14)
at Mocha.run (C:\Users\disst\AppData\Roaming\npm\node_modules\truffle\node_modules\mocha\lib\mocha.js:961:10)
at resolve (C:\Users\disst\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\testing\Test.js:149:1)
at new Promise (<anonymous>)
at Object.run (C:\Users\disst\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\testing\Test.js:148:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.59 (core: 5.1.59)
Node v10.16.0
I've been searching stackoverflow for a while but couldn't find a solution.
You should use build_directory instead of contracts_build_directory
I'm trying to make a model for my dcauser table. I get stuck because it returns an error 'Unrecognized datatype for attribute'. Now i don't know if i messed something up in the database or is sequelize not working correctly with my DB or did i mess something up in the code below. I followed some guides but i get always stuck on the same problem i mentioned above.
var Sequelize = require('sequelize');
var sequelize = new Sequelize('postgres://postgres:xpwdx#localhost:xportx/xdbx');
const UserSchema = sequelize.define(
'dcauser',
{
userid: {
type: Sequelize.Integer,
allowNull: false,
}
}
);
module.exports = UserSchema;
i get the following error:
C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\model.js:1005
throw new Error(`Unrecognized datatype for attribute "${this.name}.${name}"`);
^
Error: Unrecognized datatype for attribute "dcauser.userid"
at C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\model.js:1005:15
at C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:13401:38
at C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:4905:15
at baseForOwn (C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:2990:24)
at Function.mapValues (C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:13400:7)
at Function.init (C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\model.js:1001:28)
at Sequelize.define (C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\sequelize.js:428:11)
at Object.<anonymous> (C:\Users\luka\source\repos\dcaBotManager\src\models\user.model.js:14:30)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\luka\source\repos\dcaBotManager\src\models\index.js:2:23)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\luka\source\repos\dcaBotManager\src\config\passport.js:3:18)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
The integer keyword must be in uppercase
{
userid: {
type: Sequelize.INTEGER,
allowNull: false,
}
}
INTEGER must be in uppercase. See
https://sequelize.org/v5/manual/data-types.html
Though you should start using DataTypes.INTEGER instead.
https://sequelize.org/master/variable/index.html#static-variable-DataTypes