为什么我在ES6中的Javascript导入不起作用?意外标记*

为什么我在ES6中的Javascript导入不起作用?意外标记*,javascript,ecmascript-6,Javascript,Ecmascript 6,我目前正试图在我的项目中实现。我曾尝试通过npm安装来实现它,但不知何故,我的浏览器经常出现以下错误: Uncaught SyntaxError: Unexpected token * 我猜它与ES6有关,但我不知道如何修复它。 我的Javascript代码如下所示: import*作为“FilePond”中的FilePond; 从“filepond插件图像预览”导入FilePondPluginImagePreview; FilePond.registerPlugin( FilePondPl

我目前正试图在我的项目中实现。我曾尝试通过npm安装来实现它,但不知何故,我的浏览器经常出现以下错误:

Uncaught SyntaxError: Unexpected token *
我猜它与ES6有关,但我不知道如何修复它。 我的Javascript代码如下所示:

import*作为“FilePond”中的FilePond;
从“filepond插件图像预览”导入FilePondPluginImagePreview;
FilePond.registerPlugin(
FilePondPluginImagePreview()
);
const inputElement=document.querySelector('input[type=“file”]”);
const pond=FilePond.create(inputElement{
AllowImage预览:正确,
});
FilePond.setOptions({
服务器:'test/'

});如果要在浏览器中使用FilePond,并且要使用ES模块版本,可以使用动态导入或类型为
module
的脚本标记。浏览器支持并不是很好

另一种选择是使用库的UMD版本,只需包含文档中描述的脚本标记

第三种选择是与Babel一起使用汇总或Webpack

动态导入 删除不需要的
()

const pond = FilePond.create( inputElement,{
    allowImagePreview: true,
});

插件是自动启用的,因此也不需要将
allowmagepreview
设置为
true

您只能在模块中使用
import
。在浏览器中,您必须在
标记中包含
type=module
。您的浏览器与ES6不兼容。您可以尝试使用最新版本的Chrome,或者使用Babel将ES6编译为ES5。您可以很容易地找到教程和指南。@Pointy指出,尽管它只是更改了错误消息的文本,但它确实做了一些事情。它现在说:
Uncaught TypeError:无法设置未定义的
@Treast的属性'FilePond',所有浏览器最新版本都支持模块,而不仅仅是Chrome。如果没有类似捆绑包的网页包,您无法从
node\u模块导入。
<link href="./filepond.css" rel="stylesheet">
<input type="file"/>

<script type="module" src="./filepond.esm.js"></script>
<script>
document.addEventListener('FilePond:loaded', e => {
    const FilePond = e.detail;
    FilePond.create(document.querySelector('input'));
})
</script>
FilePond.registerPlugin(
    FilePondPluginImagePreview()
);
const pond = FilePond.create( inputElement,{
    allowImagePreview: true,
});