webpack Monaco编辑器不适用于Angular v15 -错误:未找到模块错误:请求参数不是字符串

m1m5dgzv  于 2023-02-19  发布在  Webpack
关注(0)|答案(1)|浏览(415)

环境

  • Angular -15
  • 节点. js-18.14.0
  • 摩纳哥编辑器-0.35.0
  • 摩纳哥-编辑器-网络包-插件-7.0.1

重现步骤

  • 在Angular 15项目中安装monaco-editorv0.35.0
  • 安装monaco-editor-webpack-plugin(当前为7.0.1)。
  • 添加自定义Webpack配置文件:
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const path = require("path");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    entry: {
        polyfills: './src/polyfills.ts',
        main: './src/main.ts'
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: "js/[name].[contenthash].js",
        chunkFilename: 'chunks/[name].[chunkhash].js',
        assetModuleFilename: 'media/[name][hash][ext][query]'
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    "css-loader",
                    {
                        options: {
                            url: false
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        new MonacoWebpackPlugin({
            languages: ["typescript", "javascript", "css"]
        })
    ]
};
  • angular.json中进行必要的更改:
"architect": {
  "build": {
    "builder": "@angular-builders/custom-webpack:browser",
      "options": {
        "customWebpackConfig": {
        "path": "./webpack.config.js",
        "mergeRules": {
          "externals": "replace"
        }
      },
    :
    :
    :
  }
}
  • 试试ng build

错误

出现以下错误:

./node_modules/monaco-editor/esm/vs/base/browser/ui/actionbar/actionViewItems.js:174:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/actionbar/actionbar.js:479:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/aria/aria.js:7:0-20 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/button/button.js:147:0-22 - Error: Module not found: Error: request argument is not a string
./node_modules/monaco-editor/esm/vs/base/browser/ui/checkbox/checkbox.js:147:0-24 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/codicons/codiconStyles.js:6:0-31 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/codicons/codiconStyles.js:7:0-41 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/contextview/contextview.js:146:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/countBadge/countBadge.js:54:0-26 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/dropdown/dropdown.js:146:0-24 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/dropdown/dropdownActionViewItem.js:170:0-24 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/findinput/findInput.js:123:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/findinput/replaceInput.js:147:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/hover/hoverWidget.js:121:0-21 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/iconLabel/iconLabel.js:223:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/inputbox/inputBox.js:152:0-24 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/keybindingLabel/keybindingLabel.js:153:0-31 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/list/listPaging.js:54:0-20 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/list/listWidget.js:572:0-20 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/mouseCursor/mouseCursor.js:5:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/progressbar/progressbar.js:123:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/sash/sash.js:220:0-20 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/scrollbar/scrollableElement.js:153:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/splitview/splitview.js:227:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/table/tableWidget.js:167:0-21 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/browser/ui/tree/abstractTree.js:270:0-26 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/parts/quickinput/browser/quickInput.js:603:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/parts/quickinput/browser/quickInputBox.js:124:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/parts/quickinput/browser/quickInputList.js:480:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/base/parts/quickinput/browser/quickInputUtils.js:7:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/controller/textAreaHandler.js:190:0-31 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.js:141:0-36 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/decorations/decorations.js:141:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/glyphMargin/glyphMargin.js:141:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/indentGuides/indentGuides.js:217:0-28 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/lineNumbers/lineNumbers.js:141:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/linesDecorations/linesDecorations.js:141:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/lines/viewLines.js:205:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/marginDecorations/marginDecorations.js:141:0-33 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/minimap/minimap.js:241:0-23 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.js:141:0-30 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/rulers/rulers.js:141:0-22 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.js:141:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/selections/selections.js:190:0-26 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/viewParts/viewCursors/viewCursors.js:205:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/widget/codeEditorWidget.js:254:0-28 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/widget/diffEditorWidget.js:218:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/browser/widget/diffReview.js:462:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/anchorSelect/anchorSelect.js:464:0-28 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/bracketMatching/bracketMatching.js:220:0-31 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/codeAction/lightBulbWidget.js:184:0-31 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/codelens/codelensWidget.js:77:0-30 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/colorPicker/colorPickerWidget.js:125:0-27 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/dnd/dnd.js:143:0-19 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/find/findWidget.js:485:0-26 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/folding/folding.js:212:0-23 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/gotoError/gotoErrorWidget.js:226:0-37 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition.js:116:0-40 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/gotoSymbol/peek/referencesWidget.js:603:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/inlineCompletions/ghostTextWidget.js:198:0-25 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/links/links.js:570:0-21 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/message/messageController.js:65:0-33 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/parameterHints/parameterHintsWidget.js:187:0-30 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/peekView/peekView.js:160:0-36 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/rename/renameInputField.js:112:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/snippet/snippetSession.js:165:0-30 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/suggest/suggestWidget.js:402:0-29 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/unicodeHighlighter/bannerController.js:194:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/unicodeHighlighter/unicodeHighlighter.js:552:0-34 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/contrib/zoneWidget/zoneWidget.js:105:0-26 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.js:153:0-33 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.js:141:0-32 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/standalone/browser/inspectTokens/inspectTokens.js:153:0-29 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/standalone/browser/quickInput/standaloneQuickInputServiceImpl.js:153:0-36 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/editor/standalone/browser/standaloneEditor.js:5:0-33 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/platform/actions/browser/menuEntryActionViewItem.js:604:0-39 - Error: Module not found: Error: request argument is not a string

./node_modules/monaco-editor/esm/vs/platform/contextview/browser/contextMenuHandler.js:56:0-34 - Error: Module not found: Error: request argument is not a string

Error: Module not found: Error: request argument is not a string

附加上下文

似乎monaco-editor的JS文件没有得到正确的预处理。我试过使用babel-loader,但是得到了同样的错误。可能使用正确的webpack加载程序是这里的解决方案,如果是,那么是哪一个?

ssm49v7z

ssm49v7z1#

“request argument is not a string”意味着一个库使用变量而不是字符串来导入另一个库。

const loadLibrary = async (name: string) => Promise<MyClass> {
    const { MyClass } = await import(name);
    return MyClass;
}

像Webpack这样的工具不能处理这样的导入并抛出错误。然而,它并没有什么问题,只是 Package 器的处理有限,所以我一直不明白为什么它像一个真实的的错误一样处理。
您可以忽略或抑制这些错误。

相关问题