Skip to content

fix(v2): Fix plugin path resolution - #2829

Merged
yangshun merged 2 commits into
meta:masterfrom
SamChou19815:fix-plugin-resolve
May 29, 2020
Merged

yangshun merged 2 commits into
meta:masterfrom
SamChou19815:fix-plugin-resolve

Conversation

@SamChou19815

Copy link
Copy Markdown
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

docusaurus-bot commented May 28, 2020 •

Copy link
Copy Markdown
Contributor

@SamChou19815
SamChou19815 marked this pull request as ready for review May 28, 2020 18:35
@SamChou19815
SamChou19815 requested a review from yangshun as a code owner May 28, 2020 18:35
const createRequire = Module.createRequire || Module.createRequireFromPath;
const pluginRequire = createRequire(context.siteDir);
const pluginRequire = createRequire(
join(context.siteDir, '/docusaurus.config.js'),

Copy link
Copy Markdown
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?

@yangshun yangshun left a comment

Copy link
Copy Markdown
Contributor

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 meta: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
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* fix(v2): Fix plugin path resolution

* Import docusaurus.config.js from constant file
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