首页 文章

解决发布到NPM的index.ts的出口?

提问于
浏览
0

我有一个index.ts文件this package .

node_modules/@fireflysemantics/slice 下安装的相应 index.d.ts 文件如下所示:

export { EStore } from './EStore';
export { Slice } from './Slice';
export { OStore } from './OStore';
export * from './types';

相应的 index.js 看起来像这样:

"use strict";
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var EStore_1 = require("./EStore");
exports.EStore = EStore_1.EStore;
var Slice_1 = require("./Slice");
exports.Slice = Slice_1.Slice;
var OStore_1 = require("./OStore");
exports.OStore = OStore_1.OStore;
__export(require("./types"));
//# sourceMappingURL=index.js.map

当我尝试使用Stackblitz导入 OStore 时,它不会作为根导入解析 . 例如这项工作:

import {OStore} from '@fireflysemantics/slice/OStore';

但这不是:

import {OStore} from '@fireflysemantics/slice/';

这是一个stackblitz链接,以防有用:

https://stackblitz.com/edit/typescript-vj1vpa

stackblitz错误是:

找不到模块:@fireflysemantics / slice / index.ts(@ 6.4.2)检查导入语句并确保导入正确的模块名称 .

在安装到NPM之前,是否应将 index.ts 复制到分发文件夹?

1 回答

  • 1

    导入文件夹时,如下所示:

    import {OStore} from '@fireflysemantics/slice/';
    

    它将尝试导入该文件夹中的index.ts文件 . 因此,如果错误不是模块或不存在,则会出错 .

相关问题