ES6 javascript import external js file

浪子不回头ぞ 提交于 2019-12-19 05:08:32

问题


I'm trying this in my ES6 javascript module:

import externalutil from 'https://externalutil.com/js/externalutil.js';

but it fails with this transpile error:

Module not found: 'https://externalutil.com/js/externalutil.js' 

The file externalutil.js is an old-fashioned javascript library that does not export anything.

Any help will be appreciated.


回答1:


You cannot import URL's (as of yet). You should download the file, put it somewhere locally and reference it locally as well.

However in your case, I'd just use a <script /> tag to include it in your html and just access the window object. Converting it would be more hassle than it would be beneficial.



来源:https://stackoverflow.com/questions/39892641/es6-javascript-import-external-js-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!