. Advertisement .
..3..
. Advertisement .
..4..
I have the following code and while I run it, I receive the error ”typeerror: require(…) is not a function”.
const path = require('path')
// ⛔️ TypeError: require(...) is not a function
(function () {})()
Can someone give me some advice for the error?
The cause: This error happens due to forget to place a semicolon between the
require
call, so the JavaScript engine assumed that the parenthesis surrounding our instantly invoked function expression were actually an argument list for another call of the result returned fromrequire
Solution: To solve the error, place a semicolon between your
require
call and an immediately invoked function expression and clean up any cyclic dependencies from your code.