npm install @uiw/react-codemirror --save doesn't add the correct files to node_modules

882 Views Asked by At

I'm following a tutorial for how to set up Codemirror with react. I download the package with - npm install @uiw/react-codemirror

This works, as it allows me to:

import CodeMirror from "@uiw/react-codemirror"

When I try to import themes or keymaps, however, I'm given an error:

Module not found: Error: Package path ./theme/monokai.css is not exported from package path/to/node_modules/codemirror

import "codemirror/theme/monokai.css"

Both @codemirror and codemirror are available in node_modules, however codemirror doesn't contain a themes directory.

The package.json for the codemirror directory:

{
  "name": "codemirror",
  "version": "6.0.1",
  "description": "Basic configuration for the CodeMirror code editor",
  "scripts": {
    "test": "cm-runtests",
    "prepare": "cm-buildhelper src/codemirror.ts"
  },
  "keywords": [
    "editor",
    "code"
  ],
  "author": {
    "name": "Marijn Haverbeke",
    "email": "[email protected]",
    "url": "http://marijnhaverbeke.nl"
  },
  "type": "module",
  "main": "dist/index.cjs",
  "exports": {
    "import": "./dist/index.js",
    "require": "./dist/index.cjs"
  },
  "types": "dist/index.d.ts",
  "module": "dist/index.js",
  "sideEffects": false,
  "license": "MIT",
  "dependencies": {
    "@codemirror/autocomplete": "^6.0.0",
    "@codemirror/commands": "^6.0.0",
    "@codemirror/language": "^6.0.0",
    "@codemirror/lint": "^6.0.0",
    "@codemirror/search": "^6.0.0",
    "@codemirror/state": "^6.0.0",
    "@codemirror/view": "^6.0.0"
  },
  "devDependencies": {
    "@codemirror/buildhelper": "^0.1.5"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/codemirror/basic-setup.git"
  }
}

Would be thankful for any ideas as to why I'm getting this error. I've tried uninstalling codemirror and downloading it again, however the error persists.

2

There are 2 best solutions below

0
AxelOJD On

I switched to a version of react-codemirror that downloads codemirror: 5.x and it works now

0
Abishek Kumar On

You might want to use theme doc, and doc