繁体   English   中英

使用 create react 应用程序找不到模块“monaco-editor/esm/vs/editor/editor.worker”

[英]Cannot find module 'monaco-editor/esm/vs/editor/editor.worker' with create react app

我在当前项目中使用了react-monaco-editor ,但在运行时遇到了问题。 我遵循了文档并在我的文件中进行了相应的更改。

这是我的 package.json 文件

{
  "name": "chatbot_compiler",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-monaco-editor": "^0.34.0",
    "react-scripts": "3.4.0"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-app-rewired eject",
    "lint:fix": "eslint src/**/*.js --fix"
  },
  "eslintConfig": {
    "extends": "react-app",
    "rules": {
      "indent": [
        "error",
        2
      ]
    }
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "monaco-editor-webpack-plugin": "^1.9.0",
    "prettier": "^1.19.1",
    "react-app-rewired": "^2.1.5"
  }
}

这是我的 config-overrides.js 文件

const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");

module.exports = function override(config, env) {
  config.resolve = {
    alias: {
      "monaco-editor": "monaco-editor/esm/vs/editor/editor.api.js"
    }
  };
  config.plugins.push(
    new MonacoWebpackPlugin({
      languages: ["json"]
    })
  );
  return config;
};

运行npm start时出现此错误

Cannot find module 'monaco-editor/esm/vs/editor/editor.worker'

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! chatbot_compiler@0.1.0 start: `react-app-rewired start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the chatbot_compiler@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

任何帮助将不胜感激。 提前致谢 :)

您也可以尝试安装 monaco-editor,因为它在后台使用它。 它只是一个对等依赖项,因此不会与此包一起安装。

这是版本问题,我使用"react-monaco-editor": "^0.43.0""monaco-editor-webpack-plugin": "^4.0.0",问题消失了。

暂无
暂无

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

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