Comments (8)
Let me introduce a more easy way to fix it:
// next.config.mjs
const nextConfig = {
// ... other config
experimental: {
optimizePackageImports: [
// ... other packages
+ 'shiki',
],
// ...
}
// ...
from next.js.
Currently this is the only solution, you can only import in async to ignore errors.
I'm looking at this as well.
Edit:
Top level async/await will get a warning. So we can use use
hook.
Use it in async component or dynamic import this component.
const codeHighlighterPromise = (async () => {
if (isServerSide) return
const [{ getHighlighterCore }, getWasm, { codeHighlighter }] =
await Promise.all([
import('shiki/core'),
import('shiki/wasm').then((m) => m.default),
import('./core'),
])
const core = await getHighlighterCore({
themes: [
import('shiki/themes/github-light.mjs'),
import('shiki/themes/github-dark.mjs'),
],
langs: [],
loadWasm: getWasm,
})
return {
codeHighlighter: core,
fn: (o: { lang: string; attrs: string; code: string }) => {
return codeHighlighter(core, o)
},
}
})()
export const ShikiHighLighter: FC<Props> = (props) => {
const { lang: language, content: value, attrs } = props
const codeHighlighter = use(codeHighlighterPromise)
// ...
}
from next.js.
https://github.com/dev-pi2pie/next-v14_2-with-rehype-pretty-code-and-shiki-transformer
I've made a repo which reproducing the similar issue which happened on the build stage.
And this repo is a simple editor, which input something like markdown syntax to the text area and get the result back.
And the issue happened in the code:
I think the issue is from the code:
import {
transformerNotationDiff,
transformerNotationWordHighlight,
transformerNotationHighlight,
} from "@shikijs/transformers";
If I do not use the transformers
in the rehype-pretty-code
, and the build will be success.
However, good to see @arvinxx mentioned the issue I encountered too.
from next.js.
Good, after I got the solution from @Innei provided --> quick link
I tried this solution in the repo, which I made for reproducing this issue before.
I made a new branch, and tried this solution, and it works.
(with dynamic import
)
The new branch in the repo for reproducing this issue:
with-dynamic-import
Key diff code in src/app/page.tsx
:
import { EditorProvider } from "@/components/editor/editorContext";
- import EditorResult from "@/components/editor/editorResult";
import EditorTextArea from "@/components/editor/editorTextArea";
+ import dynamic from "next/dynamic";
export default function Home() {
+ const EditorResult = dynamic(
+ () => import("@/components/editor/editorResult"),
+ { ssr: false }
+ );
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<EditorProvider>
<div className="lg:max-w-[1024px] mx-auto flex flex-col gap-5 mt-10 p-2">
<h1>Editor</h1>
<EditorTextArea className="text-black" />
<article className="prose dark:text-white dark:prose-headings:text-white">
<EditorResult />
</article>
</div>
</EditorProvider>
</main>
);
}
Thanks @Innei pointed out the solution
from next.js.
Hi @arvinxx, thanks for sharing, really a good solution, nice! 👍
I add this solution to a new branch in the repo which I made for reproducing this issue.
new branch:
with-optimize-package-imports
from next.js.
i have also faced similar issue. i was using nextra with app router.
this following package is creating problem from nextra: @theguild/remark-mermaid
from next.js.
me too
Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!
from next.js.
same error here
Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!
from next.js.
Related Issues (20)
- Metadata is not generated for intercepting routes HOT 1
- Monorepo self-referencing package imports don't resolve in certain cases with Turbopack
- Creating instance of URL with basePath gets mangled HOT 1
- Creating instance of URL with basePath gets mangled HOT 3
- Regression since `v14.2.0-canary.24`: `loading.tsx` triggered on first `revalidatePath()` call HOT 3
- Nested parallel routes slot rendered after navigating back HOT 3
- graphql-request and caching HOT 4
- Client side navigation not working properly in latest next@rc for dev HOT 3
- Intercepted route not generating metadata
- `static` Router Cache is used once, the value of `staleTimes.dynamic` is applied the next time. HOT 4
- Nextjs reloads page when i go to not-found page HOT 2
- page arises a error everytime when app republished
- Getting redirected to the copied link unexpectedly. HOT 1
- Modal by parallel routing on slow connection not working. Clicking on Link before hydration causes full reload instead of showing modal HOT 2
- ChunkLoadError: Loading chunk app/layout failed. (timeout: http://localhost:3000/_next/static/chunks/app/layout.js) HOT 7
- ISR: Cached 404 status never change even if page is not a not-found anymore HOT 2
- Suspense does not work with Next.js 15 RC and Vercel HOT 2
- Custom events don't work in custom elements
- Tailwindcss content when using src directory HOT 1
- Flask + NextJs works locally but Flask api do not work on Vercel HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.