-
Notifications
You must be signed in to change notification settings - Fork 194
Closed
Description
What happens
When I try to import a custom React component that uses a 3rd party packages into my MDX files, I get this error:
> ../components/LibTest.jsx:1:23: error: Could not resolve "date-fns" (mark it as external to exclude it from the bundle)
1 │ import { format } from 'date-fns'
╵ ~~~~~~~~~~
Error: Found 1 problems in 1 documents.
└── Encountered unexpected errors while processing of 1 documents. This is possibly a bug in Contentlayer. Please open an issue.
• "test/components-import.md": UnexpectedMDXError: Error: Build failed with 1 error:
../components/LibTest.jsx:1:23: error: Could not resolve "date-fns" (mark it as external to exclude it from the bundle)
The component I'm trying to import:
// LibTest.jsx
import { format } from 'date-fns'
export default function LibTest() {
return <p>{format(new Date(2014, 1, 11), 'yyyy-MM-dd')}</p>
}However, when I try to define this component directly in my MDX file and import the package it depends on, everything works just fine.
### Some MDX file
Lorem ipsum ...
import { format } from 'date-fns'
export function LibTest() {
return <p>{format(new Date(2014, 1, 11), 'yyyy-MM-dd')}</p>
}
<LibTest/>Steps to reproduce
- Clone this repo: https://github.com/flowershow/flowershow
- Go to
templates/defaultand runnpm installandnpm run dev - Open
site/content/test/components-import.md - Go to "Importing a custom component that uses a 3rd party package" section and uncomment these two lines:
{/*import LibTest from "../components/custom/LibTest.jsx"*/}
{/*<LibTest/>*/}- Go to the next section: "Importing and using external package directly in MDX" and comment out/remove these lines:
import { format } from 'date-fns'
export function LibTest() {
return <p>{format(new Date(2014, 1, 11), 'yyyy-MM-dd')}</p>
}
<LibTest/>
- 🐛 You should see the above error in the console.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels