Skip to content

[Bug] Can't require yarn-resolved path (PNP) #1467

Closed
@samtstern

Description

  • I'd be willing to implement a fix

Describe the bug

Requiring a module like this throws an error:

require(require.resolve(<name>, { paths: [ <working_directory> ] }))

To Reproduce

Reproduction

With yarn2 and PNP require.resolve() returns some funny paths, which I know is expected:

function requireLocal(frb: FunctionsRuntimeBundle, name: string) {
  const path = require.resolve(name, { paths: [frb.cwd] });
  console.log(`requireLocal: ${path}`);
  return require(path);
}

I get the following error:

>  requireLocal: /Users/samstern/Scratch/firebase-functions-yarn-2/.yarn/$$virtual/firebase-functions-virtual-5ee8699f73/0/cache/firebase-functions-npm-3.7.0-5eb6b20443-1.zip/node_modules/firebase-functions/lib/index.js
⚠  functions: Cannot find module '/Users/samstern/Scratch/firebase-functions-yarn-2/.yarn/$$virtual/firebase-functions-virtual-5ee8699f73/0/cache/firebase-functions-npm-3.7.0-5eb6b20443-1.zip/node_modules/firebase-functions/lib/index.js'
Require stack:

Seems like require.resolve is working fine but then require on the resulting path causes an error. I need to require this specific path to make sure I am picking up the dependency from the developer's functions directory.

Screenshots

N/A

Environment if relevant (please complete the following information):

  • OS: macOS
  • Node version: v10.19.0
  • Yarn version: 2.0.0-rc.27

Additional context

N/A

Activity

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

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

        翻译: