Closed DefectingCat closed 2 years ago
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.
You can try this version for now:
npm install @code-hike/mdx@0.4.0-next.3
You can try this version for now:
npm install @code-hike/mdx@0.4.0-next.3
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 with yarn dev
. thank you.
But i got some new errors when i visit my mdx page:
error - SyntaxError: Named export 'SandpackClient' not found. The requested module '@codesandbox/sandpack-client' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@codesandbox/sandpack-client';
const { SandpackClient } = pkg;
Here is call stack:
Call Stack
<unknown>
file:///E:/Git/DefectingCat.github.io/node_modules/@code-hike/mdx/dist/components.esm.mjs (4)
ModuleJob._instantiate
node:internal/modules/esm/module_job (127:21)
async ModuleJob.run
node:internal/modules/esm/module_job (193:5)
async ESMLoader.import
node:internal/modules/esm/loader (337:24)
async importModuleDynamicallyWrapper
node:internal/vm/module (437:15)
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.mjs
file:
import remarkFrontmatter from 'remark-frontmatter';
import mdx from '@next/mdx';
// import rehypePrism from '@mapbox/rehype-prism';
import composePlugins from 'next-compose-plugins';
import remarkGfm from 'remark-gfm';
import rehypeSlug from 'rehype-slug';
import { remarkCodeHike } from '@code-hike/mdx';
const composedConfig = composePlugins([
mdx({
extension: /\.mdx?$/,
options: {
remarkPlugins: [remarkFrontmatter, remarkGfm, [remarkCodeHike]],
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'],
},
]);
export default composedConfig;
I don't know how rollup work with .mjs, hope these information can provide a littile help
I couldn't reproduce it. It will help if you can create a minimal repo so I can debug it.
I couldn't reproduce it. It will help if you can create a minimal repo so I can debug it.
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/hello
to reproduce it.
Ok, @code-hike/mdx@0.4.0-next.6
should fix your issue.
There's an issue with React 18 though. I'm tracking it here #161
Ok,
@code-hike/mdx@0.4.0-next.6
should fix your issue. There's an issue with React 18 though. I'm tracking it here #161
It;s works with React 17. Thank you.
:rocket: Issue was released in v0.4.0
:rocket:
The next.js config is cjs file. But some remark plugins only provide esm packages, so i change my
next.config.js
tonext.config.mjs
and use it like:I need use codeHike with remark plugins together, i tried:
Well, import is OK, but i got erros:
I need a little help