yapi 引入第三方包【@monaco-editor/react】报错 Module parse failed You may need an appropriate loader to handle this file type

7y4bm7vi  于 2021-11-29  发布在  Java
关注(0)|答案(0)|浏览(1174)

版本号

~ 最新版

什么问题

~ Yapi二次开发,引入monaco-editor ,【@monaco-editor/react】报错 Module parse failed You may need an appropriate loader to handle this file type

本地用create-app创建一个工程,不报错

ykit是有什么特殊配置导致?

如何复现此问题

~
Step1 安装包: npm install @monaco-editor/react
Step2 组件代码
`

  1. import React from 'react';
  2. import MonacoEditor from '@monaco-editor/react';
  3. const MoEditor = () => {
  4. const classes = {
  5. width: '100%',
  6. height: '100%',
  7. display: 'flex',
  8. justifyContent: 'space-between',
  9. padding: 5,
  10. 'padding-top': 15,
  11. 'margin-bottom': 15,
  12. };
  13. const language = 'javascript';
  14. const examples = `// code here `
  15. return (
  16. <div className={classes.root}>
  17. <MonacoEditor
  18. height="100vh"
  19. path={language}
  20. defaultValue={examples || ''}
  21. defaultLanguage={language}
  22. />
  23. </div>
  24. )
  25. }
  26. export default MoEditor;

`

Step3 在主页面homejs引入 Moditor组件

启动dev-clinet 报错

`

  1. [error] in ./~/@monaco-editor/react/lib/cjs/DiffEditor/DiffEditor.js
  2. Module parse failed: D:\code\yapi-code\vendors\node_modules\@monaco-editor\react\lib\cjs\DiffEditor\DiffEditor.js Unexpec
  3. ted token (102:6)
  4. You may need an appropriate loader to handle this file type.
  5. SyntaxError: Unexpected token (102:6)
  6. @ ./~/@monaco-editor/react/lib/cjs/DiffEditor/index.js 6:17-43
  7. [error] in ./~/@monaco-editor/react/lib/cjs/Editor/Editor.js
  8. Module parse failed: D:\code\yapi-code\vendors\node_modules\@monaco-editor\react\lib\cjs\Editor\Editor.js Unexpected toke
  9. n (116:6)
  10. You may need an appropriate loader to handle this file type.
  11. SyntaxError: Unexpected token (116:6)
  12. @ ./~/@monaco-editor/react/lib/cjs/Editor/index.js 6:13-35
  13. × [17:12:44] 3 errors in compiling process.

`

什么浏览器

~ chrome

什么系统(Linux, Windows, macOS)

~ window

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题