Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot find module "." When I use require.context #4772

Description

@yleo77

Do you want to request a feature or report a bug?

Bug

What is the current behavior?
The code snippet should work as expected, I think. But in fact, it's not work as expected when i using Identifier instead of Literal.

var regexp = /^\.\/.*\.js$/;
var req = require.context("./templates", false, regexp);   // Uncaught Error

var bool = false;
var req = require.context("./templates", bool, /^\.\/.*\.js$/);   // Uncaught Error

var dir = "./templates";
var req = require.context(dir, false, /^\.\/.*\.js$/);   // Uncaught Error

If the current behavior is a bug, please provide the steps to reproduce.

main.js (or anywhere in javascript files)

var regexp = /^\.\/.*\.js$/;
var req = require.context("./templates", false, regexp);   // Uncaught Error

This code above the line can reproduce the bug.

What is the expected behavior?
No Error. When i use Identifier instead of Literal.

Please mention other relevant information such as the browser version, Node.js version, webpack
version and Operating System.

Max OS X 10.12
Node 7.8.0
webpack 1.x 2.x

FYI, I found the return value at L17 in lib/dependencies/RequireContextDependencyParserPlugin.js file is wrong, the expected type is a RegExp, But it's not in fact.

Further info, something about evaluate in Parser.js, for example:

this.plugin("evaluate Identifier", function(expr) {
  //...
  if(this.scope.definitions.indexOf(expr.name) === -1) {	
  //...
  } else {
    return this.applyPluginsBailResult1("evaluate defined Identifier " + name, expr);
  }
});

But I don't find this.plugin("evaluate defined Identifier", function(expr) {...});, am i missing something?

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

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions