Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(void 0) is not a function #9

Open
542154968 opened this issue Oct 9, 2022 · 4 comments
Open

(void 0) is not a function #9

542154968 opened this issue Oct 9, 2022 · 4 comments

Comments

@542154968
Copy link

依赖

{
  "name": "computing-platform",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "sea": "vite --mode sea",
    "build": "vue-tsc --noEmit && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@element-plus/icons-vue": "^2.0.9",
    "@types/node": "^18.7.15",
    "axios": "^0.27.2",
    "blockly": "^8.0.5",
    "element-plus": "^2.2.16",
    "mavon-editor": "^3.0.0-beta",
    "monaco-editor": "^0.34.0",
    "vue": "^3.2.37",
    "vue-router": "^4.1.5"
  },
  "devDependencies": {
    "@iconify-json/ep": "^1.1.7",
    "@vitejs/plugin-vue": "^3.0.3",
    "sass": "^1.54.8",
    "sass-loader": "^13.0.2",
    "typescript": "^4.6.4",
    "unplugin-auto-import": "^0.11.2",
    "unplugin-icons": "^0.14.9",
    "unplugin-vue-components": "^0.22.4",
    "vite": "^3.0.7",
    "vite-plugin-html": "^3.2.0",
    "vite-plugin-monaco-editor-nls": "^2.0.2",
    "vue-tsc": "^0.39.5"
  }
}

配置

import { defineConfig } from "vite";
import { loadEnv } from "vite";
import zh_CN from "./src/plugins/monaco-editor/vscode-language-pack-zh-hans/main.i18n.json";

import MonacoEditorNlsPlugin, {
  esbuildPluginMonacoEditorNls,
  Languages,
} from "vite-plugin-monaco-editor-nls";



// https://vitejs.dev/config/
export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return defineConfig({
    base: "./",
  
    optimizeDeps: {
      /** vite 版本需要大于等于2.3.0 */
      esbuildOptions: {
        plugins: [
          esbuildPluginMonacoEditorNls({
            locale: Languages.zh_hans,
            /**
             * The weight of `localedata` is higher than that of `locale`
             */
            localeData: zh_CN.contents,
          }),
        ],
      },
    },
    
    plugins: [
      MonacoEditorNlsPlugin.default({
        locale: Languages.zh_hans,
        /**
         * The weight of `localedata` is higher than that of `locale`
         */
        localeData: zh_CN.contents,
      }),
    ],
    
    
  });
};

报错

image

vue-router.mjs:3441 TypeError: (void 0) is not a function
    at node_modules/monaco-editor/esm/vs/base/common/platform.js (platform.js:41:34)
    at __init (chunk-MB5FDF5C.js?v=3fbab092:9:56)
    at editorOptions.js:6:1

image

@542154968
Copy link
Author

我找到了另一种汉化的解决方案

<template>
  <div ref="divRef" style="height: 500px; width: 500px"></div>
</template>

<script lang="ts" setup>
import loader from "@monaco-editor/loader";
import * as monaco from "monaco-editor";
const divRef = ref();

loader.config({ monaco });
loader.config({
  "vs/nls": {
    // availableLanguages: { "*": "de" },
    availableLanguages: { "*": "zh-cn" },
  },
});

loader.init().then(monacoInstance => {
  monacoInstance.editor.create(divRef.value, {
    value: "321313123",
  });
});
</script>

<style lang="scss"></style>

image

@liuyike98
Copy link

你这还引入monaco干嘛,走的是cdn,不信你开审查元素看看。。。我已经试过了

@JackieCheung
Copy link

同样的问题

@dyimo
Copy link

dyimo commented Jul 19, 2024

你这还引入monaco干嘛,走的是cdn,不信你开审查元素看看。。。我已经试过了

这种方法没有走cdn吧,走的本地npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants