正在解析发布到 NPM 的 index.ts 的导出?
Resolving exports from of index.ts published to NPM?
我 this package 有一个 index.ts 文件。
安装在 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 link 以防有帮助:
https://stackblitz.com/edit/typescript-vj1vpa
stackblitz 错误是:
Can't find module:
@fireflysemantics/slice/index.ts (@6.4.2) Check your import statements & ensure you're importing the correct module names.
在安装到 NPM 之前,是否应该 index.ts
复制到分发文件夹?
当您像这样导入文件夹时:
import {OStore} from '@fireflysemantics/slice/';
它将尝试导入该文件夹中的 index.ts 文件。因此,如果它不是模块或不存在,则会出现错误。
我 this package 有一个 index.ts 文件。
安装在 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 link 以防有帮助:
https://stackblitz.com/edit/typescript-vj1vpa
stackblitz 错误是:
Can't find module: @fireflysemantics/slice/index.ts (@6.4.2) Check your import statements & ensure you're importing the correct module names.
在安装到 NPM 之前,是否应该 index.ts
复制到分发文件夹?
当您像这样导入文件夹时:
import {OStore} from '@fireflysemantics/slice/';
它将尝试导入该文件夹中的 index.ts 文件。因此,如果它不是模块或不存在,则会出现错误。