nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
105.15k stars 28.49k forks source link

thread closes without error when module.export function is undefined #11315

Closed chevalierc closed 7 years ago

chevalierc commented 7 years ago

If the module.exports option points to an undefined function (in my case a misspelling of a function) the node thread closes without an error during the require function. I feel some error is needed.

var curRoute = require( '/workout.js')( app, express ); //Node thread coses here silently

//workout.js

buildWorkout = function(){
return true
}
module.exports = {
    build_workout: build_workout
}
addaleax commented 7 years ago

I feel some error is needed.

You will get an error if you add a 'use strict'; line at the top of your files (which I’d recommend always doing). ;)

I don’t think Node.js can or should forbid people from having their module exports contain undefined values, though.

chevalierc commented 7 years ago

Thanks for the heads up!

I don’t think Node.js can or should forbid people from having their module exports contain undefined values, though.

I agree that you should be allowed to include undefined variables in the module but you get an error calling an undefined function anywhere else in node.js

> foo()
ReferenceError: bloo is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
    at REPLServer.Interface._ttyWrite (readline.js:827:14)
>

Sorry if I'm mistaken. Won't pretend I'm the most knowledgeable in this field.

addaleax commented 7 years ago

I agree that you should be allowed to include undefined variables in the module but you get an error calling an undefined function anywhere else in node.js

You’re right, you should get that for calling any undefined function, including the ones exported by your module… if that is not the case for you, could you share a full reproduction of the problem?

chevalierc commented 7 years ago

I will try to create something In the next few days. Again, thanks for the help!

seishun commented 7 years ago

Can't reproduce:

C:\Users\Nikolai\Desktop\test\workout.js:5
    build_workout: build_workout
                   ^

ReferenceError: build_workout is not defined
    at Object.<anonymous> (C:\Users\Nikolai\Desktop\test\workout.js:5:20)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\Nikolai\Desktop\test\test.js:1:78)
    at Module._compile (module.js:571:32)
chevalierc commented 7 years ago

Sorry for any distractions today.

I kept running into the problem of the thread just closing at random times at weird and random places (I wouldn't change anything and it would break at a different place)

reverting to my last commit it would run fine. Reverting to the head again, it would occur again (back and forth this occurred)...

Downloading the zip of my head (the same copy causing the strange behavior) off the GitHub site and running that copy (and in the same location on my drive) no issues at all!...

So I have no idea how to explain what was happening but I seem to have ridden myself of the problem.

Impressed by the quick responses of your team. Keep up the good work.

seishun commented 7 years ago

Alright, let us know if you find a reliable way to reproduce this issue.