【问题标题】:Consuming Dexie as a module使用 Dexie 作为一个模块
【发布时间】:2020-03-27 17:08:59
【问题描述】:

我刚刚开始使用 Dexie。我在尝试遵循 Consuming Dexie as a module 的简短版本示例时遇到了一个我不理解的错误。我有以下源文件:

index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Dexie Test</title>
  <style>
  </style>
</head>

<body>
  <script src="./mytest.js" type="module"></script>
</body>

</html>

mydb.js

import Dexie from './dexie.js';

const db = new Dexie('myDb');
db.version(1).stores({
  friends: 'name, age'
});

export default db;

mytest.js

import db from './mydb.js';

console.log(db.name);

当我从本地 Web 服务器运行此程序时,我收到以下错误:

Uncaught SyntaxError: The requested module './dexie.js' does not provide an export named 'default'

【问题讨论】:

    标签: dexie


    【解决方案1】:

    要使用 Dexie 的 ES 模块版本,您需要 dexie.mjs 而不是来自https://unpkg.com/dexie@^3.0.0-rc.1/dist/dexie.mjs 的 dexie.js。或者,如果您从 node_modules 中选择它,请确保您已安装 dexie@next 或 dexie@^3.0.0-rc.1。

    【讨论】:

    • 我还发现标准的npm包包含dexie.es.js,也解决了这个问题。很高兴听到 3.0 即将到来。
    猜你喜欢
    • 2020-09-05
    • 2015-10-23
    • 2017-11-13
    • 2020-07-02
    • 2015-07-23
    • 2021-11-15
    • 2014-01-12
    • 2011-04-01
    • 2017-06-21
    相关资源
    最近更新 更多