[英]Vue-konva running into error: Must use import to load ES Module
I am trying to implement the Vue-konva
into my application by following the documentation here .我正在尝试按照此处的文档将
Vue-konva
到我的应用程序中。 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:我做了以下步骤:
npm install vue-konva konva --save
and npm install canvas --save
.npm install vue-konva konva --save
和npm install canvas --save
。Vue
app from the documentation .Vue
应用程序中的代码。 Following things I tried for work-around:以下是我尝试解决的方法:
node version v14.16.0
node version v14.16.0
package.json
file:package.json
文件中添加了以下内容:"ssr": false,
"type":"module",
node-modules
folder and create again with npm-install
.node-modules
文件夹并使用npm-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
**更新** 我试图喜欢这个并得到错误,
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>
This one should work fine这个应该可以正常工作
<script>
import Vue from 'vue'
export default {
async mounted () {
if (process.browser) {
const VueKonva = await import('vue-konva')
Vue.use(VueKonva)
console.log('HELLO FROM MOUNTED')
}
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.