In ordinary node.js server side (an ubuntu server), I have a file
// admin.js
..
function tell(msg) {
console.log(msg)
}
..
exports.tell = tell
(it does more than just the log, but I reduced it to that to eliminate any other variable issues.)
Then, in dozens of files of the app and in 100s of places, let’s say main.js, I do
// main.js
const tell = require('./tell')
..
app.get('/hook', (req, res) => {
admin.tell(`blah..`)
..
async function handleCommand(m, whomIndex) {
..
catch (error) {
admin.tell(`blah..`)
etc etc. This works perfectly and has for years.
However today, in main.js, I simply had this:
// main.js
const tell = require('./tell')
..
// anywhere in the file at top level:
console.log("yo") // works fine
admin.tell(`blah.. // ERROR
and similarly in a first-level function:
// main.js
const tell = require('./tell')
..
// anywhere in the file at top level:
function apnsSetup() {
console.log("yo") // works fine
admin.tell(`blah..`) // ERROR
the error being simply:
/home/ubuntu/main/main.js:666
admin.tell("wtf")
^
TypeError: admin.tell is not a function
I must be misunderstanding something basic about node.js??
I carefully tested in different files, with different functions etc. and I always get the behavior.
Lost!
PS again just TBC this has nothing to do with browser-side code (which I don’t do and don’t know about! 🙂 ) Vanilla node.js in a typical express/mysql/etc node.js app on an aws ubuntu instance.