【问题标题】:Import mathjs as a JavaScript module fails将 mathjs 作为 JavaScript 模块导入失败
【发布时间】:2020-04-30 06:14:23
【问题描述】:

我尝试在浏览器(客户端)中将mathjs 作为模块导入。我在服务器上复制了this file,然后尝试导入js模块,但是总是失败。以下是我已经做过的一些试验:

import { mathjs } from "./math.min.js"

SyntaxError: 请求的模块 './../modules/math.min.js' 没有 提供一个名为“mathjs”的导出

import { math } from "./math.min.js"

SyntaxError: 请求的模块 './../modules/math.min.js' 没有 提供一个名为“math”的导出

import { create, all } from "./math.min.js"

语法错误:请求的模块“./math.min.js”未提供名为“all”的导出

我也试试:

import("/math.min.js");

Uncaught (in promise) TypeError: Cannot set property 'math' of undefined

注意路径没问题,我查过了。我可能遗漏了一些东西,但我找不到我做错了什么。欢迎任何帮助。

这是一个 repl.it 代码:https://repl.it/@FifiLulu/NewJollyRoutes

【问题讨论】:

    标签: javascript module mathjs


    【解决方案1】:

    您需要添加:

    <script type="module">
    

    到您的 html 文件。

    【讨论】:

    • 这不是问题。文件 index.js 使用import("/index.js") 导入。它适用于其他模块。
    猜你喜欢
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    相关资源
    最近更新 更多