Skip to content

Cannot find package.json in path #81

@elfenheart

Description

@elfenheart

Hi,

I'm using module-alias with ncc compiler (https://github.com/zeit/ncc) and seeing weird behavior. If I run the code without the ncc compiler, then it's working fine. However, after ncc compiler, then module-alias is throwing error that it cannot find package.json at some path, even though the path does contain package.json file.

I tried with passing a static path for the module-alias init, and still getting the same error.

After debugging and trying to modify the code of module-alias, I find that if I were to add a temporary variable to join the path first, before the npmPackage require being called, then things will work.

line 171

for (var i in candidatePackagePaths) {
    try {
      base = candidatePackagePaths[i]

      var packageJsonPath = nodePath.join(base, 'package.json')
      npmPackage = require(packageJsonPath)
      break
    } catch (e) {
      // noop
    }
  }

I'm not really sure why assigning the path to a temporary variable before require fixes the problem. Any idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions