javascript - 导入 javascript 类时出错
问题描述
更新
我换了
import {WaveSurfer} from "js/wavesurfer.js/src/wavesurfer.js"
经过
import WaveSurfer from "./js/wavesurfer.js/src/wavesurfer.js"
现在似乎已导入,但我现在收到以下错误:
SyntaxError: bad method definition (wavesurfer.js:179:4)
(请参见此处的相应行)
我正在尝试从wavesurfer.js运行一个示例,其中包含代码的本地克隆。
使用下面显示的代码,我得到
SyntaxError: import declarations may only appear at top level of a module (wavesurfer.js:1)
按照此处给出的建议,我将第一行替换index.html
为
<script type='module'>
import {WaveSurfer} from "js/wavesurfer.js/src/wavesurfer.js"
</script>
并得到
ReferenceError: WaveSurfer is not defined (zoom.js:1:5)
TypeError: Error resolving module specifier: js/wavesurfer.js src/wavesurfer.js index.html:4:25
我应该如何导入WaveSurfer
?
索引.html
<script src="js/wavesurfer.js/src/wavesurfer.js"></script>
<script src="js/zoom.js"></script>
<div id="waveform"></div>
...
缩放.js
var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'red',
progressColor: 'purple'
});
wavesurfer.load('https://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3');
...
解决方案
希望这行得通。尝试相对路径。
<script type='module'>
import { WaveSurfer } from "./src/wavesurfer.js"
</script>
推荐阅读
- excel - 试图总结一列,但有些列包含需要存在的字符
- r - 递归地将`unnest_wider()`应用于所有列,直到没有更多的嵌套列表列?
- vue.js - 如何通过对象选项在完整日历中使用 EXDATE
- tableau-api - 如何在行中使用列标题将列移动到行(特殊情况)
- ruby-on-rails - MongoDB 验证从 has_and_belongs_to_many 关系失败
- matplotlib - 如何将 Arduino 信号从 Python 转换为快速傅里叶变换?
- reactjs - 我不知道如何处理这个 ReactJS 问题
- javascript - 在 useEffect 中从数组中添加数字
- java - 如何查看try块中catch的变化?
- pine-script - 我如何用颜色填充这个 EMA 图表