Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Module not found: Can't resolve '@milkdown/theme-nord/style.css' in Nextjs #1596

Open
2 tasks done
mandatoryGithubUser opened this issue Dec 19, 2024 · 2 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@mandatoryGithubUser
Copy link

Initial checklist

  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything (or linked relevant results below)

Affected packages and versions

7.5.9

Link to runnable example

No response

Steps to reproduce

Add nord and theme-nord imports to Nextjs 15 project using React 19.

import { nord } from '@milkdown/theme-nord'
import '@milkdown/theme-nord/style.css'

Run pnpm dev and navigate the the page with Milkdown Editor. Note there's a build error

Import trace for requested module:
./src/app/page.tsx
 ⨯ ./src/app/(milkdown)/MilkdownEditorWrapper.tsx:17:1
Module not found: Can't resolve '@milkdown/theme-nord/style.css'
  15 |
  16 | import { nord } from '@milkdown/theme-nord'
> 17 | import '@milkdown/theme-nord/style.css'
     | ^
https://nextjs.org/docs/messages/module-not-found

Expected behavior

Should be able to import the css without this error

Actual behavior

Cannot build as nextjs cannot find the css file

Runtime

Firefox

OS

Linux

Build and bundle tools

Next.js

@mandatoryGithubUser mandatoryGithubUser added the bug Something isn't working label Dec 19, 2024
@mandatoryGithubUser
Copy link
Author

mandatoryGithubUser commented Dec 19, 2024

App Versions

    "@milkdown/kit": "^7.5.9",
    "@milkdown/react": "^7.5.9",
    "@milkdown/theme-nord": "^7.5.9",
    "next": "^15.1.1",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",

Editor

'use client'

import React, { useEffect } from 'react'
import {
    defaultValueCtx,
    Editor,
    editorViewCtx,
    rootCtx,
} from '@milkdown/kit/core'
import { nord } from '@milkdown/theme-nord'
import { Milkdown, useEditor } from '@milkdown/react'
import { commonmark } from '@milkdown/kit/preset/commonmark'

import '@milkdown/theme-nord/style.css'

const markdown = `

`

export const MilkdownEditor = () => {
    const { loading, get } = useEditor(root => {
        return Editor.make()
            .config(nord)
            .config(ctx => {
                ctx.set(rootCtx, root)
                ctx.set(defaultValueCtx, markdown)
            })
            .use(commonmark)
    }, [])

    useEffect(() => {
        if (loading) return

        const editor = get()
        if (!editor) return

        // Autofocus the editor after it's init
        editor.ctx.get(editorViewCtx).dom.focus()
    }, [loading])

    return <Milkdown />
}

export default MilkdownEditor

@mandatoryGithubUser
Copy link
Author

Just added some styles manually as a temp fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants