【问题标题】:Jest: Cannot find module 'monaco-editor-core'开玩笑:找不到模块“monaco-editor-core”
【发布时间】:2021-11-21 08:27:45
【问题描述】:

我有一个 reactjs(typescript) 应用程序,它使用自定义语言的 monaco-editor-core,而不是 monaco-editor。如果我不模拟 monaco-editor-core 导入,Jest 测试会失败,并出现下一个错误:

"Cannot find module 'monaco-editor-core'", 

从我阅读的帖子中,我了解到 jest 不支持 ESM。这就是为什么写了 monaco-editor-webpack-plugin,它不适用于 monaco-editor-core。 也许有人知道我该如何解决 monaco-editor-core for jest 的导入问题?

  • 开玩笑:26.4.2
  • ts-jest: 26.3.0
  • 打字稿:3.9.5
  • 反应:16.9.0
  • monaco-editor-core: 0.21.3
  • webpack:4.42.1

如果我在 jest.config.js 中使用 moduleNameMapper:

"monaco-editor-core": "<rootDir>/node_modules/monaco-editor-core/esm/vs/editor/editor.api.d.ts"

我有下一个错误:

 .../node_modules/monaco-editor-core/esm/vs/editor/editor.api.d.ts:6
    declare global {
            ^^^^^^

    SyntaxError: Unexpected identifier at compileFunction (<anonymous>)

如果您需要任何可以提供帮助的其他信息,请发表评论。

PS:我不能把它标记为 monaco-editor-core...

感谢您的帮助!

【问题讨论】:

    标签: typescript jestjs monaco-editor ts-jest


    【解决方案1】:

    将此添加到我的jest.config.json 对我有用:

    "transformIgnorePatterns": [
        "node_modules\/(?!(monaco-editor|monaco-editor-core)\/)"
    ]
    

    【讨论】:

      猜你喜欢
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      • 2021-05-02
      • 2021-12-09
      相关资源
      最近更新 更多