简体   繁体   English

无法在javascript中导入模块

[英]Cannot import modules in javascript

I have a script with imports. 我有一个导入脚本。

I am getting an error on the very first one. 我在第一个错误。

It's not a 404 but a 不是404,而是

plyr.js:8 
Uncaught SyntaxError: Unexpected identifier

The modules are on the correct path. 模块在正确的路径上。

Heres the code that crashes: 这是崩溃的代码:

// ==========================================================================
// Plyr
// plyr.js v3.4.3
// https://github.com/sampotts/plyr
// License: The MIT License (MIT)
// ==========================================================================

import captions from './captions';
........

Pretty much a newbie on modules so I'm not sure where to make adjustments. 几乎是模块上的新手,所以我不确定在哪里进行调整。

You need to be using the scripts built on dist not the ones on src . 您需要使用基于dist而不是src上构建的脚本。 The project uses gulp to build the files needed for the browser. 该项目使用gulp构建浏览器所需的文件。 You can build them yourself, if you find yourself on a branch without an updated dist folder: 如果发现自己位于没有更新的dist文件夹的分支中,则可以自己构建它们:

npm run build

You need to download its dev dependencies though. 不过,您需要下载其开发依赖项。

我认为正确的道路是

    import captions from '.src/js/captions';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM