I am trying to implement the Vue-konva
into my application by following the documentation here. But I am running into the following error:
Must use import to load ES Module: /Users/myName/projects/projectName/node_modules/konva/lib/index-node.js require() of ES modules is not supported.
require() of /Users/myName/projects/projectName/node_modules/konva/lib/index-node.js from /Users/myName/projects/projectName/node_modules/vue-konva/umd/vue-konva.js is an ES module file as it is a .js file whose nearest parent package.json
contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index-node.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/myName/projects/projectName/node_modules/konva/package.json.
I did the following steps:
- Install
npm install vue-konva konva --save
andnpm install canvas --save
. - Added the code in my
Vue
app from the documentation. - When I restart the application I get the error.
Following things I tried for work-around:
- I am using
node version v14.16.0
- I added the following in my
package.json
file:
"ssr": false,
"type":"module",
- Remove
node-modules
folder and create again withnpm-install
.
I feel like I am doing everything that has been mentioned in the documentation but still not sure why I am getting the error. Can someone please help me with this issue?
Here is the complete code from the application:
<template>
<v-stage :config="configKonva">
<v-layer>
<v-circle :config="configCircle" />
</v-layer>
</v-stage>
</template>
<script>
import Vue from 'vue'
import VueKonva from 'vue-konva'
Vue.use(VueKonva)
export default {
data () {
return {
configKonva: {
width: 200,
height: 200
},
configCircle: {
x: 100,
y: 100,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
}
}
}
}
</script>
<style>
body {
margin: 0;
padding: 0;
}
</style>
** UPDATED **
I tried to like this and got the error, client.js:227 TypeError: Vue.use is not a function
<template>
<v-stage :config="configKonva">
<v-layer>
<v-circle :config="configCircle" />
</v-layer>
</v-stage>
</template>
<script>
export default {
data () {
return {
configKonva: {
width: 200,
height: 200
},
configCircle: {
x: 100,
y: 100,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
}
}
},
async mounted () {
if (process.browser) {
const Vue = await import('vue')
const VueKonva = await import("vue-konva")
Vue.use(VueKonva)
console.log('HELLO FROM MOUNTED')
}
}
}
</script>