To use imports in the browser, the file that does the imports needs to
(要在浏览器中使用导入,执行导入的文件需要)
a) be included with type="module"
:
(a)包含在type="module"
:)
<script src="./workout.js" type="module"></script>
b) it only works for script
s that are remote (that is, have a src
attribute), it does not work for inline scripts.
(b)它仅适用于远程script
(即具有src
属性的脚本),不适用于嵌入式脚本。)
Also note that you cannot shorthand reference files from node_modules
in the browser, that only works when run with Node.
(还要注意,您不能从浏览器的node_modules
速记引用文件,仅当与Node一起运行时才起作用。)
So, inside your workout.js, start like this:
(因此,在您的execution.js中,开始如下:)
import 'https://github.com/nefe/number-precision/blob/master/build/index.iife.js';
Unfortunately, that library author does not seem to supply a true ES6 module version ( I've just opened an issue on that ), so you cannot proceed like the page suggests and import the script into a variable NP
.
(不幸的是,该库作者似乎没有提供真正的ES6模块版本( 我刚刚打开了一个问题 ),因此您无法像页面上所建议的那样继续进行并将脚本导入到变量NP
。)
Executing the script like the import shown above should work for you, though, and expose the library in the global namespace.
(不过,执行上述显示的导入之类的脚本应该可以为您工作,并在全局名称空间中公开该库。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…