简体   繁体   English

解决从index.ts发布到NPM的导出问题?

[英]Resolving exports from of index.ts published to NPM?

I have this package with an index.ts file. 我有一个带有index.ts文件的软件包

The corresponding index.d.ts file that is installed under node_modules/@fireflysemantics/slice looks like this: 安装在node_modules/@fireflysemantics/slice下的相应index.d.ts文件如下所示:

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

The corresponding index.js looks like this: 相应的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

When I try to import the OStore using Stackblitz it will not resolve as a root import. 当我尝试导入OStore使用Stackblitz它无法解决作为根进口。 For example this work: 例如,这项工作:

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

But this does not: 但这不是:

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

Here's a stackblitz link in case that's helpful: 这是一个有帮助的stackblitz链接:

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

The stackblitz error is: stackblitz错误为:

Can't find module: @fireflysemantics/slice/index.ts (@6.4.2) Check your import statements & ensure you're importing the correct module names. 找不到模块:@ fireflysemantics / slice / index.ts(@ 6.4.2)检查您的导入语句并确保您导入的模块名称正确。

Should index.ts be copied to the distribution folder before installing to NPM? 在安装到NPM之前,应将index.ts复制到分发文件夹吗?

When you import a folder like you are doing with: 当您像执行以下操作一样导入文件夹时:

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

It will try to import the index.ts file in that folder. 它将尝试导入该文件夹中的index.ts文件。 Hence, the error if its not a module or it does not exist. 因此,如果该错误不是模块或不存在,则为错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM