I can not import my published typescript library, with this error: "Module not found: Can't resolve 'tqt' in ..."

I can not import my published typescript library, with this error: "Module not found: Can't resolve 'tqt' in ..."

我使用这个 tutorial 发布了一个非常简单的打字稿模块,它是通过

安装的
npm install --save tqt@1.0.0

当尝试在程序中使用它时,我得到这个:

Module not found: Can't resolve 'tqt' in '/home/akiva/Programming/frogcast/src'

来自这个:

import React from "react";
import { CA_PoliticalParty } from "tqt";

console.log(CA_PoliticalParty); // Anything that invokes this will error.
class App extends React.Component
{
    constructor() {
        super("");
    }
    render() { return ( <div> </div> )};
};

export default App;

发布的相关代码是这样的:

TQt.ts

// Canadian Enumerators
export enum CA_PoliticalParty {
    // Canadian Major National Political Parties
    None= "None",
    CPC = "CPC",
    GPC = "GPC",
    LPC = "LPC",
    NDP = "NDP",
    PPC = "PPC",
}

index.ts

export {CA_PoliticalParty} from './TQt'

package.json

{
  "name": "tqt",
  "version": "1.0.0",
  "description": "Typescript Namespaces and Enums",
  "main": "index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "Akiva Avraham <akiva@linux.com>",
  "license": "GPL-2.0",
  "repository": {
    "type": "git",
    "url": "git+ssh://akiva@git.launchpad.net/tqt"
  },
  "devDependencies": {
    "typescript": "^3.6.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "declaration": true,
    "outDir": "./dist", 
    "lib": ["es5","es6","dom"]
  },
  "include": [
    "src/**/*"
  ]
}

这里有什么明显的遗漏吗?我只是以非常小的方式尝试了这些设置,没有做任何更改,并且我完全按照教程的布局进行了操作。

问题是 TypeScript outDir 与 package.json main 不匹配。对于您的特定设置,如果您将 main 更改为 dist/index.js(这与您为 types 所做的正确操作平行)

,它将起作用