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 does not work as described in the documentation #18695
I guess this how to interpret the module loading logic - my annotations in grey:
Input: X=./hello Y=/require_test
If X begins with './' or '/' or '../' [TRUE]
a. LOAD_AS_FILE(Y + X) ['/require_test' + './hello'] = ['./require_test/hello']
b. LOAD_AS_DIRECTORY(Y + X)
LOAD_NODE_MODULES(X, dirname(Y))
THROW "not found"
LOAD_AS_FILE(X) [X='./require_test/hello'] [FAILS AS X is a folder now]
If X is a file, load X as JavaScript text. STOP
If X.js is a file, load X.js as JavaScript text. STOP
If X.json is a file, parse X.json to a JavaScript Object. STOP
If X.node is a file, load X.node as binary addon. STOP
LOAD_AS_DIRECTORY(X) X=['./require_test/hello']
If X/package.json is a file, [TRUE]
a. Parse X/package.json, and look for "main" field. [TRUE], test
b. let M = X + (json main field) ./require_test/hello/test
c. LOAD_AS_FILE(M) DONE!
It is working as per the documentation. Closing as answered, let me know if you think otherwise.
It is handled as semver-major because it was wrong for a very long time and there is a chance that code relies on the faulty behavior. So it will only be released in v.10.0.0.
@BridgeAR / @richardlau - can you please clarify for my understanding? - I don't see any deviation from the doc, nor I see a doc update as part of #15015!
LOAD_AS_FILE(X) [X='./require_test/hello'] [FAILS AS X is a folder now]
This describes the incorrect behaviour, it should not fail here and X should be tried as a file. #15015 fixes the behaviour so that it matches the doc.
Activity
gireeshpunathil commentedon Mar 29, 2018
I guess this how to interpret the module loading logic - my annotations in grey:
Input:
X=./helloY=/require_test[TRUE]a. LOAD_AS_FILE(Y + X)
['/require_test' + './hello'] = ['./require_test/hello']b. LOAD_AS_DIRECTORY(Y + X)
LOAD_AS_FILE(X)
[X='./require_test/hello'][FAILS AS X is a folder now]LOAD_AS_DIRECTORY(X)
X=['./require_test/hello'][TRUE]a. Parse X/package.json, and look for "main" field.
[TRUE], testb. let M = X + (json main field)
./require_test/hello/testc. LOAD_AS_FILE(M)
DONE!It is working as per the documentation. Closing as answered, let me know if you think otherwise.
richardlau commentedon Mar 29, 2018
I think this is addressed by #15015?
BridgeAR commentedon Mar 29, 2018
@smkoyan this was indeed a bug and it was fixed recently. It was fixed recently by #15015.
BridgeAR commentedon Mar 29, 2018
@richardlau racy :D
It is handled as semver-major because it was wrong for a very long time and there is a chance that code relies on the faulty behavior. So it will only be released in v.10.0.0.
gireeshpunathil commentedon Mar 29, 2018
@BridgeAR / @richardlau - can you please clarify for my understanding? - I don't see any deviation from the doc, nor I see a doc update as part of #15015!
richardlau commentedon Mar 29, 2018
@gireeshpunathil the issue is this part of your annotations:
This describes the incorrect behaviour, it should not fail here and X should be tried as a file. #15015 fixes the behaviour so that it matches the doc.
gireeshpunathil commentedon Mar 29, 2018
ah! ok, thanks @richardlau for the clarification.