rete: Cannot read property 'style' of null
I’m using vue cli 3 to generate the project.
Then my component:
<template>
<div id="rete" class="node-editor"></div>
</template>
<script>
import Rete from 'rete';
// import ConnectionPlugin from 'rete-connection-plugin';
import VueRenderPlugin from 'rete-vue-render-plugin';
import CustomNodeComponent from './CustomNodeComponent.vue';
import CustomControlComponent from './CustomControlComponent.vue';
const container = document.querySelector('#rete');
const editor = new Rete.NodeEditor('demo@0.1.0', container);
editor.use(VueRenderPlugin);
class MyComponent extends Rete.Component {
constructor() {
super();
this.data.render = 'vue';
this.data.component = CustomNodeComponent;
this.data.props = {};
}
}
class MyControl extends Rete.Control {
constructor() {
super();
this.data.render = 'vue';
this.data.component = CustomControlComponent;
this.data.props = {};
}
}
const myComponent = new MyComponent();
editor.register(myComponent);
const myControl = new MyControl();
editor.register(myControl);
export default {
name: 'Flow',
mounted() {
},
};
</script>
<style scoped lang="scss">
</style>
On launch, I’m not getting anything rendered, and get

The error appear to be at line 15 of my code
L15 -> const editor = new Rete.NodeEditor('demo@0.1.0', container);
rete.esm.js -> _this.view = new EditorView(container, _this.components, _assertThisInitialized(_this));
rete.esm.js -> _this.container.style.overflow = 'hidden';
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (6 by maintainers)
@Ni55aN I was going to suggest the refs method but I’m still reading up on it. Also it’s a bit hard for a newbie like me to grok the layout of the examples in the retejs repo since these are done dynamically. Could you make a simple barebones example based on a new vue cli project with the best practices? The threejs example on codesandbox is also a bit heavy I fear.
obviously, since you have no nodes
Test (dont forget async mounted())
Parent of #rete element should have a sizes (and
editor.view.resize()of course)#rete element doesn’t exist when the
querySelectorcalling. All initial operations with HTML elements in template must by performed inmounted(). Moreover, querySelector is a bad practive for Vue.js - use a $refsI had this exact issue Saturday when I picked up this library since it’s been a minute since I have used Vue so fairly new to this whole babel webpack thing and also first time using the cli (
vue uiis super cool as well). The issue is that the element isn’t ready when the script runs that portion of code. My solution might not be the best or correct but what worked for me is to your functionality into either anawaitcall somewhere or perform this somewhere insidemounted() {}My setup currently looks like this
To keep your single file component clean I would also recommend doing something like
<script src="./Rete.js"></script>instead of chucking all your js inside as it can get unwieldy fast.Note that I put
async init, this is to make sure you can makeawaitcalls inside the function as you might need to do so when creating components.This is just one part however and you will probably run into https://github.com/retejs/rete/issues/247 right after.
To fix that as well add
@babel/plugin-transform-regenerator": "^7.0.0"andbabel-polyfill": "^6.26.0"to your dependencies and follow the instructions in this comment https://github.com/retejs/rete/issues/247#issuecomment-459411540.To continue documenting what I went through to get this working, also make sure that your rete
divhas at least the explicit height set for its style or it won’t be visible.I would also recommend sticking to pure javacript for writing your js, adding typescript introduces a slew of issues so if you want to get something up and running without a bunch of fiddling don’t branch off.