Node error: internal/modules/cjs/loader.js:960 - node.js

After updating to BigSur OS started to get the following error when trying to start the application.
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module '/Users/anton/Documents/WebDev/_corporate/app.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Cannot figure out how to resolve this issue.

Related

Nodejs. why I caught TypeError error but process still exited?

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!

Node File System unstable

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?

index.handler is undefined or not exported AWS

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) {
}

TypeError: contracts_build_directory is not a function

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

internal/modules/cjs/loader.js:969 throw err; ^ Error: Cannot find module 'F:\mernbootcamp\harrycodname

internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'F:\mernbootcamp\harrycode\D1'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

Resources