汇总无法看到来自commonjs模块的命名导出

时间:2018-01-04 18:23:23

标签: node.js typescript rollup rollupjs

我有一个简单的AWS Lambda函数(state-info.ts),我正在使用 Rollup 进行抖动,它给了我以下错误:

  

[!]错误:' DB'不是由../../ forest-fire / abstracted-admin / lib / index.js

导出的
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
src/state-info.ts (10:9)
8: import { Lambda } from "aws-sdk";
9: import { STATES } from "./models/shared";
10: import { DB } from "abstracted-admin";
            ^
11: import { StateInfo } from "./models/StateInfo";
12: import { IApiResponse } from "./shared/ApiRetriever";

现在恰巧我写了一个模块abstracted-admin(当前在npm的v0.6.5)它正在抱怨并且它将 DB 导出为命名导出(< em>和作为默认导出)。但由于某些原因,Rollup不满意。

我已经为完整背景创建了所有内容的视频演示:video

对于那些不喜欢视频的人,以下是关键事实/文件:

abstracted-admin/lib/index.d.ts

import { DB } from "./db";
export default DB;
export { DB, IFirebaseConfig, IFirebaseListener } from "./db";

abstracted-admin/lib/index.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const db_1 = require("./db");
exports.default = db_1.DB;
var db_2 = require("./db");
exports.DB = db_2.DB;

并且来自abstracted-admin/package.json

{
  ...
  "files": ["lib"],
  "main": "lib/index.js",
  "typings": "lib/index.d.ts",
}

state-info.ts(又名,正在汇总的文件):

import {
  IDictionary,
  AWSGatewayCallback,
  IAWSGatewayRequest,
  IAWSGatewayResponse
} from "common-types";
import GetStateInfo from "./vote-smart/get-state-info";
import { Lambda } from "aws-sdk";
import { STATES } from "./models/shared";
import { DB } from "abstracted-admin";
import { StateInfo } from "./models/StateInfo";
import { IApiResponse } from "./shared/ApiRetriever";
/** ... */

同时我的汇总配置是:

import cjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
import json from "rollup-plugin-json";
import ts from "rollup-plugin-typescript2";
import globals from "rollup-plugin-node-globals";

export default {
  input: "src/state-info.ts",
  output: {
    file: "lib/state-info-rolled.js",
    format: "cjs"
  },
  external: ["aws-sdk"],
  plugins: [
    globals(),
    json(),
    cjs({
      include: "node_modules/**",
      exclude: ["node_modules/aws-sdk/**"]
    }),
    ts(),
    resolve({
      jsnext: true,
      main: true,
      browser: false,
      preferBuiltins: false,
      extensions: [".js", ".json"]
    })
  ]
};

1 个答案:

答案 0 :(得分:0)

我相信Rollup在这种情况下期待以下情况:

<?php
                                include("appconnect.php");
                                $sql = "SELECT app_id, firstname, journeydate, appl_type, passportno, arrivalport, birthdate, phone FROM tblapps";
                                $result = $connect->query($sql);
                                if ($result->num_rows > 0) {

                                echo "<table class="table table-bordered table-striped table-condensed flip-content">

                                        <tr>

                                            <th>App ID</th><th>Name</th><th>Journey Date</th><th>App type</th><th>Passport No</th><th>Arrival Port</th><th>BirthDate</th><th>Phone</th>

                                        </tr>";

                                    // output data of each row
                                         while($row = $result->fetch_assoc()) {
                                         echo"<tr>

                                            <td>" . $row["app_id"]. "</td><td>" . $row["firstname"]. "</td><td>" . $row["journeydate"]. "</td><td>" . $row["appl_type"]. "</td><td>" . $row["passportno"]. "</td><td>" . $row["arrivalport"]. "</td><td>" . $row["birthdate"]. "</td><td>" . $row["phone"]. "</td></tr>";
    }
                                echo "</table>";
                                } else {
    echo "0 results";
}

$connect->close();
?>

它与Webpack的行为不同,并且已经抓住了我几次。