Skip to content

feature request: strict mode for synchronous require() calls #51

Open

Description

@dgoldstein0

Currently, code that looks like

define(["require"], function(require) { var x = require("X"); x.doSomething(); ...})

is valid and works if the module "X" is already loaded by the time this executes. That said, this is fragile code - nothing here guarantees that "X" is already loaded. It would be really useful if we could ban such code, e.g. via a config flag such that the local require() function would throw if the module did not declare the passed in string as a dep. That is, the code sample would instead be required to look like

define(["require", "X"], function(require) { var x = require("X"); x.doSomething(); ...})

I don't think the same change can be easily made to the global require() & requirejs() functions, but it's possible to ban usage of those in a codebase via types, convention, lint, or other static analysis that specifically looks for global variable usage.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions