Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

new require('foo') doesn't resolve `foo` #563

Closed
robotlolita opened this Issue · 3 comments

2 participants

@robotlolita

Given the following JS file:

new require('data.persistent')

And the following Browserify command:

$ npm install data.persistent
$ $(npm bin)/browserify -e input.js > output.js

The output.js file is compiled without resolving and bundling the require dependency. Wrapping the require call in parenthesis, however, works:

new (require('data.persistent')) // resolves the stuff

Browserify version is the latest in NPM: 3.14.0

@jhnns
new require('data.persistent')

is not the same like

new (require('data.persistent'))

The former will call require() with a new context, the latter will call the result of require('data.persistent') with a new context.

Since calling require() with a new context doesn't make sense at all new (require('data.persistent')) is the only valid syntax. You should also add () at the end because omitting them obfuscates the function call:

new (require('data.persistent'))()
@robotlolita

Sure, it's not the same. But this is not the point of this issue.

Actually, nevermind. I just realised I'm being stupid. I should probably get more sleep.

@wilmoore wilmoore referenced this issue in eslint/eslint
Closed

Rule: Disallow new require #847

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.