Repository navigation
Closed
Description
The next.js config is cjs file. But some remark plugins only provide esm packages, so i change my next.config.js to next.config.mjs and use it like:
import remarkGfm from 'remark-gfm';
import rehypeSlug from 'rehype-slug';
const composedConfig = composePlugins([
mdx({
extension: /\.mdx?$/,
options: {
remarkPlugins: [
remarkFrontmatter,
// [remarkToc, { maxDepth: 2 }],
remarkGfm,
],
rehypePlugins: [rehypePrism, rehypeSlug],
providerImportSource: '@mdx-js/react',
},
}),
/** @type {import('next').NextConfig} */
{
reactStrictMode: true,
// experimental: {
// reactMode: 'concurrent',
// },
experimental: {
outputStandalone: true,
},
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
},
]);I need use codeHike with remark plugins together, i tried:
import remarkGfm from 'remark-gfm';
import rehypeSlug from 'rehype-slug';
import codeHike from '@code-hike/mdx';
const { remarkCodeHike } = codeHike;
const composedConfig = composePlugins([
mdx({
extension: /\.mdx?$/,
options: {
remarkPlugins: [
remarkFrontmatter,
// [remarkToc, { maxDepth: 2 }],
[remarkCodeHike],
remarkGfm,
],
rehypePlugins: [rehypePrism, rehypeSlug],
providerImportSource: '@mdx-js/react',
},
}),
/** @type {import('next').NextConfig} */
{
reactStrictMode: true,
// experimental: {
// reactMode: 'concurrent',
// },
experimental: {
outputStandalone: true,
},
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
},
]);Well, import is OK, but i got erros:
error - Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error
C:\Users\someone\Git\someproject\node_modules\@code-hike\mdx\dist\index.esm.js:1
import { FontStyle, setCDN, getHighlighter } from 'shiki';
^^^^^^
SyntaxError: Cannot use import statement outside a module
I need a little help
Metadata
Metadata
Assignees
Labels
No labels
Activity
pomber commentedon Apr 15, 2022
Hmm, nextjs isn't loading codehike as an es module. I'm going to rename codehike index.esm.js to .mjs and publish a new version.
pomber commentedon Apr 15, 2022
You can try this version for now:
DefectingCat commentedon Apr 17, 2022
I tried with
@code-hike/mdx@0.4.0-next.3, now next.js loading codehike as an es module, i can start a dev server withyarn dev. thank you.But i got some new errors when i visit my mdx page:
Here is call stack:
Seems when i use .mjs file, the sandpcak-client is a CommonJS module. it's cannot work with
import { SandpackClient } from '@codesandbox/sandpack-client';My mdx file just have basic markdown syntax. and i am not use another highlight plugin.
Here is my
next.config.mjsfile:I don't know how rollup work with .mjs, hope these information can provide a littile help
pomber commentedon Apr 18, 2022
I couldn't reproduce it. It will help if you can create a minimal repo so I can debug it.
DefectingCat commentedon Apr 20, 2022
Hi, i create a minimal repo, https://github.com/DefectingCat/code-hike-test.
It's installed mdx plugin and
@code-hike/mdx@0.4.0-next.3.Please visit
http://localhost:3000/helloto reproduce it.pomber commentedon Apr 21, 2022
Ok,
@code-hike/mdx@0.4.0-next.6should fix your issue.There's an issue with React 18 though. I'm tracking it here #161
DefectingCat commentedon Apr 22, 2022
It;s works with React 17. Thank you.
github-actions commentedon Apr 28, 2022
🚀 Issue was released in
v0.4.0🚀