facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
55.55k stars 8.33k forks source link

Error when importing Docusaurus Swizzle component into Netlify CMS #9837

Closed niravbhuva99 closed 7 months ago

niravbhuva99 commented 7 months ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

I am encountering an error when attempting to import a Docusaurus Swizzle component into Netlify CMS. For each Docusaurus client API component used within the Swizzle component, Webpack throws an error.

Reproducible demo

No response

Steps to reproduce

  1. Navigate to the repository.
  2. Run npm install to install all the dependencies.
  3. Go to the static/admin/customEditor/editor.tsx file.
  4. Import any Swizzle component from the src/theme directory that uses Docusaurus client API components.
  5. Run npm start to start the development server.
  6. Observe the error thrown by webpack when trying to import the Swizzle component.

Expected behavior

Upon importing a Docusaurus Swizzle component into Netlify CMS, webpack should successfully resolve the imports of Docusaurus client API components within the Swizzle component without throwing any errors.

Actual behavior

Error Example

When including a Docusaurus component such as Link within the Swizzle component, Webpack throws the following error:

Screenshot 2024-02-08 at 17 28 21

Your environment

Self-service

slorber commented 7 months ago

This is not related to Docusaurus.

You are getting this error while running webpack --mode production on a custom Webpack config file you have in your project, which we are not responsible for because it is not something we provide you.

So, this is not a Docusaurus bug. At best, I can help you if you have specific questions. But please assume I don't know anything about NetlifyCMS and don't plan to study your custom setup in depth to figure out what you are doing.

Note that NetlifyCMS is not maintained anymore, and has a new name DecapCMS now: https://www.netlify.com/blog/netlify-cms-to-become-decap-cms/

You are not even using the latest version of Docusaurus.

It's hard to even help you if you use older versions of projects, even more if we do not even know these projects well ourselves (such as NetlifyCMS)


You probably misunderstand how Webpack resolves aliases, and should read more carefully this documentation:

https://webpack.js.org/configuration/resolve/#resolvealias

I'd suggest using absolute paths instead of relative paths, and use an exhaustive list of exact match aliases instead of @docusaurus, because @docusaurus will also match @docusaurus/whatever/comes/after.