question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: this.require is not a function

See original GitHub issue

write demo according to the readme , get exception:

TypeError: this.require is not a function
    at VueComponent.mounted (vue-monaco.common.js?70e3:75)
    at callHook (vue.esm.js?efeb:2921)
    at Object.insert (vue.esm.js?efeb:4158)
    at invokeInsertHook (vue.esm.js?efeb:5960)
    at Vue.patch [as __patch__] (vue.esm.js?efeb:6179)
    at Vue._update (vue.esm.js?efeb:2660)
    at Vue.updateComponent (vue.esm.js?efeb:2788)
    at Watcher.get (vue.esm.js?efeb:3142)
    at new Watcher (vue.esm.js?efeb:3131)
    at mountComponent (vue.esm.js?efeb:2795)

demo code:

  1. App.vue
<script src="../node_modules/monaco-editor-core/min/vs/loader.js"></script>
<script>
 require.config({
   paths: {
     vs: '../node_modules/monaco-editor-core/min/vs'
   }
 })
</script>

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

2.helloworld.vue

<template>
  <monaco-editor
    class="editor"
    v-model="code"
    language="javascript">
  </monaco-editor>
</template>

<script>
import MonacoEditor from 'vue-monaco'

export default {
  components: {
    MonacoEditor
  },

  data () {
    return {
      code: 'const noop = () => {}'
    }
  }
}
</script>

<style>
  .editor {
    width: 600px;
    height: 800px;
  }
</style>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
MaChristmanncommented, Apr 24, 2018

Same here.

It is probably related that we use webpack to bundle our application. To my understanding webpack is not able to resolve the AMD require statement if we dynamically assign window.require to a property

    require: {
      type: Function,
      default: window.require
    }

I forked the project and run a quick test using just require(… instead of this.require and it worked for me. https://github.com/MaChristmann/vue-monaco/commit/da7b97764f46d94b638ec35e1ba8879c49a2a179

1reaction
damylencommented, Jul 18, 2018

@MaChristmann nice, do you have an example package.json, how to integrate your version in a project? If I use it in a project (vue-cli), like this:

   "vue-monaco": "MaChristmann/vue-monaco#da7b977",
   "monaco-editor": "^0.13.1",

I get the following error:

This dependency was not found:

* vue-monaco

To install it, you can run: npm install --save vue-monaco                                                                                                                    No type errors found
Version: typescript 2.9.2

running npm/yarn doesn’t throw any errors

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJs : TypeError: require(...) is not a function - Stack Overflow
I have read that this usually means that requireJS is not getting loaded properly yet I am not aware why or how to...
Read more >
TypeError: require(...) is not a function · Issue #12990 - GitHub
When i run npm start , its show error like above. var model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes); TypeError: ...
Read more >
NodeJs : TypeError: require(...) is not a function - SyntaxFix
I think this means that module.exports in your ./app/routes module is not assigned to be a function so therefore require('./app/routes') ...
Read more >
TypeError require(…) is not a function || NodeJs - YouTube
In this video We will solve NodeJs TypeError require(…) is not a function Error Please follow the Video for Solving this Error.
Read more >
JavaScript : NodeJs : TypeError: require(...) is not a function
JavaScript : NodeJs : TypeError : require(...) is not a function [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found