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

fix(v2): Fix plugin path resolution #2829

Merged
merged 2 commits into from
May 29, 2020
Merged

fix(v2): Fix plugin path resolution #2829

merged 2 commits into from
May 29, 2020

Conversation

SamChou19815
Copy link
Contributor

Motivation

Actually fix #2825. It seems like createRequire expects a path to a nodejs module instead of a folder where the package.json happens to live in. The module would be docusaurus.config.js, which is guaranteed to exist in the root docusaurus project folder.

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

  1. Create a new docusaurus project.
  2. Install @docusaurus/plugin-ideal-image.
  3. yarn start, it will fail with the error in Error: Cannot find module '@docusaurus/plugin-ideal-image' #2825.
  4. Edit node_modules and manually apply the fix in this PR.
  5. yarn start, it will now succeed.

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 28, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented May 28, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 71a4667

https://deploy-preview-2829--docusaurus-2.netlify.app

@SamChou19815 SamChou19815 marked this pull request as ready for review May 28, 2020 18:35
@@ -21,7 +22,9 @@ export function initPlugins({
// We need to fallback to createRequireFromPath since createRequire is only available in node v12.
// See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
const createRequire = Module.createRequire || Module.createRequireFromPath;
const pluginRequire = createRequire(context.siteDir);
const pluginRequire = createRequire(
join(context.siteDir, '/docusaurus.config.js'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you import this from the constants file?

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@yangshun yangshun merged commit f2fb2b8 into facebook:master May 29, 2020
@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Jun 17, 2020
@SamChou19815 SamChou19815 deleted the fix-plugin-resolve branch June 19, 2020 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Cannot find module '@docusaurus/plugin-ideal-image'
5 participants