如何在没有捆绑器的情况下导出 TS 以供使用?

问题描述 投票:0回答:1

我有一个像这样的

package.json
的小包裹:

{
  "name": "@nomatter/utils",
  "license": "MIT",
  "author": "Dave Stein",
  "version": "0.0.1",
  "scripts": {
    "tsc:watch": "tsc --watch --preserveWatchOutput"
  },
  "type": "module",
  "main": "out-tsc/src/index.js",
  "types": "out-tsc/src/index.d.ts",
  "dependencies": {
    "typescript": "^4.9.5",
    "yup": "^0.32.11"
  },
  "devDependencies": {},
  "description": ""
}

我的导出包中的 TS Config 和导入它的应用程序如下(除了

declaration
仅在导出包中):

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "lib": ["es2017", "dom"],
    "strict": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "outDir": "out-tsc",
    "sourceMap": true,
    "inlineSources": true,
    "rootDir": "./",
    "incremental": true,
    "declaration": true
  },
  "include": ["**/*.ts"],
}

我似乎无法在

main
中找到
types
package.json
的正确配置。

在我执行

import @nomatter/utils
的应用程序中,TSC 编译器会抱怨它无法解析我的导入。

我认为 TSC 可以处理读取从 TSC 生成的导入

js
文件。当我查看
out-tsc/src/index.js
时,它有一个基本的
export
,我希望它基于所有配置都存在。不知道为什么找不到它?

index.ts
只是
export const signupSchema = {};
index.d.ts
只是
export declare const signupSchema: {};

typescript package.json tsconfig
1个回答
0
投票

这是正确的,正如我原来的问题所示。

  "type": "module",
  "main": "out-tsc/src/index.js",
  "types": "out-tsc/src/index.d.ts",

正如@jsejckson 所暗示的,我的符号链接很糟糕。使用

npm link
正确解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.