You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
require should treat "." and ".." like any other directory names #1178
I too once expected require('.') to work, but turns out you need to do require('./'). Is there a specific reason we need that trailing slash inside therequire path?
Here's the current error:
> require('.')
Error: Cannot find module '.'
at Function.Module._resolveFilename (module.js:320:15)
at Function.Module._load (module.js:262:25)
at Module.require (module.js:349:17)
at require (module.js:368:17)
at repl:1:1
at REPLServer.defaultEval (repl.js:116:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:269:12)
at emitOne (events.js:77:13)
Good suggestion. I (and whoever wrote those module parts) didn't even think about module names starting with dots. I wonder if these are valid npm module names (e.g. they can be published).
They are not valid module names, npm forbids anything starting with a dot, see validate-npm-package.
So it's purely for consistency reasons. Right now you can create file named "..foo.js" and require('..foo') it. It looks like a module, but it's not. I'd like to discourage that.
Activity
silverwind commentedon Mar 17, 2015
I too once expected
require('.')to work, but turns out you need to dorequire('./'). Is there a specific reason we need that trailing slash inside therequirepath?Here's the current error:
rvagg commentedon Mar 18, 2015
I can't think of a good reason so I'm +1 on this unless someone comes up with something, perhaps @isaacs can chime in?
targos commentedon Mar 18, 2015
@smcmurray
require('..')does already load the correct filemodule: allow require('.')
silverwind commentedon Mar 20, 2015
Fixed by 6fc5e95
rlidwka commentedon Apr 7, 2015
@silverwind ,
I know it's nitpicking, but...
..testis still treated incorrectly (as a local file, but it should be a module).Since we're bikeshedding the hell out of it anyway, my suggestion for
iojs@2.0is this:silverwind commentedon Apr 7, 2015
Good suggestion. I (and whoever wrote those module parts) didn't even think about module names starting with dots. I wonder if these are valid npm module names (e.g. they can be published).
rlidwka commentedon Apr 7, 2015
They are not valid module names, npm forbids anything starting with a dot, see validate-npm-package.
So it's purely for consistency reasons. Right now you can create file named "..foo.js" and
require('..foo')it. It looks like a module, but it's not. I'd like to discourage that.