我正在努力实施Vue-konva
按照以下步骤进入我的应用程序文档在这里 https://www.npmjs.com/package/vue-konva。但我遇到了以下错误:
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.
我执行了以下步骤:
- Install
npm install vue-konva konva --save
and npm install canvas --save
.
- 添加了我的代码
Vue
应用程序来自文档 https://www.npmjs.com/package/vue-konva#:%7E:text=3%20Reference%20in%20your%20component%20templates.
- 当我重新启动应用程序时,我收到错误。
我尝试解决以下问题:
- 我在用
node version v14.16.0
- 我在我的中添加了以下内容
package.json
file:
"ssr": false,
"type":"module",
- Remove
node-modules
文件夹并再次创建npm-install
.
我觉得我正在执行文档中提到的所有操作,但仍然不确定为什么会收到错误。有人可以帮我解决这个问题吗?
以下是应用程序的完整代码:
<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**
我尝试喜欢这个并收到错误,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>