I published a dead simple typescript module using this tutorial, and it is installed via
npm install --save tqt@1.0.0
When trying to use it in a program, I get this:
Module not found: Can't resolve 'tqt' in '/home/akiva/Programming/frogcast/src'
from this:
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;
With the relevant code that was published being this:
// Canadian Enumerators
export enum CA_PoliticalParty {
// Canadian Major National Political Parties
None= "None",
CPC = "CPC",
GPC = "GPC",
LPC = "LPC",
NDP = "NDP",
PPC = "PPC",
}
export {CA_PoliticalParty} from './TQt'
{
"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"
}
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"declaration": true,
"outDir": "./dist",
"lib": ["es5","es6","dom"]
},
"include": [
"src/**/*"
]
}
Is there anything obvious I am missing here? I played around with the settings only in very minor ways with no changes, and I followed the tutorial exactly as it is laid out.
The problem is that the TypeScript outDir
does not match the package.json main
. For your particular setup, it will work if you change main
to dist/index.js
(which is parallel to what you did correctly for types
.)