简体   繁体   English

npm install @uiw/react-codemirror --save 没有将正确的文件添加到 node_modules

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

I'm following a tutorial for how to set up Codemirror with react.我正在关注如何使用 React 设置 Codemirror 的教程 I download the package with - npm install @uiw/react-codemirror我下载 package - 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找不到模块:错误:Package path./theme/monokai.css 未从 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. @codemirror 和 codemirror 都在 node_modules 中可用,但是 codemirror 不包含主题目录。

The package.json for the codemirror directory: package.json为codemirror目录:

{
  "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": "marijnh@gmail.com",
    "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.我尝试卸载 codemirror 并重新下载,但错误仍然存在。

I switched to a version of react-codemirror that downloads codemirror: 5.x and it works now我切换到下载 codemirror: 5.x 的 react-codemirror 版本,现在可以使用

You might want to use theme doc , and doc您可能想使用theme docdoc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM