Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[commonjs] require.resolve is rewritten #406

Closed
tkalliom opened this issue May 22, 2020 · 2 comments
Closed

[commonjs] require.resolve is rewritten #406

tkalliom opened this issue May 22, 2020 · 2 comments

Comments

@tkalliom
Copy link

  • Rollup Plugin Name: commonjs
  • Rollup Plugin Version: 12.0.0
  • Rollup Version: 2.10.7
  • Operating System (or Browser): Linux
  • Node Version: 10.19.0

How Do We Reproduce?

See https://repl.it/repls/RobustConcreteHypertalk for a complete example.

Module:

module.exports.getLocation = function() {
  return require.resolve("./rollup.config.json");
}

Input:

import { getLocation } from "locator";

console.log("Location of config is " + getLocation());

Expected Behavior

Rollup leaves require.resolve as-is, because no actual requiring is performed.

Actual Behavior

Rollup replaces require with commonjsRequire, causing the error commonjsRequire.resolve is not a function.

@thecotne
Copy link

thecotne commented Jun 7, 2020

as a workaround you can replace commonjsRequire.resolve with require.resolve from output plugins

export default {
  // ...
  output: {
    // ...
    plugins: [
      replace({ 'commonjsRequire.resolve': 'require.resolve' })
    ]
  }
}

@tkalliom
Copy link
Author

tkalliom commented Aug 6, 2020

This was fixed by #446

@tkalliom tkalliom closed this as completed Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants