Skip to content

Issue with multiple calls to loadModule within a loader #2299

@beauroberts

Description

@beauroberts

I've written a loader to handle JSON files with a schema that looks like this:

{
  "imports": [
     "some-loader!./subdir_1/a.json",
     "some-loader!./subdir_2/b.json"
  ],
  ...
}

I'm using this.loadModule within my loader to handle the imports. The first imported module loads without issue, but I get an error on the second:

Module not found: Error: Can't resolve './subdir_2/b.json' in './subdir_1'

Note that the context being used for the resolve is subdir_1. I think this is down to this line in lib/dependencies/LoaderPlugin.js, where module is being replaced by dep.module. The module path is being resolved using the context of the last module that was loaded, rather than the context of the module that's doing the loading.

A workaround is to pass absolute paths to this.loadModule.

I think this applies to both webpack 1 and webpack 2.

I have a failing test and a proposed fix that I'll submit in a pull request.

Thanks for supporting an incredible tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions