Project Description
I am currently developing a customized TypeScript type declaration library that will be utilized in various projects. However, I am encountering an issue when it comes to importing this TypeScript library into my projects. Although it does import, I consistently receive the error message: Module not found
.
Steps Taken So Far
- I attempted to make modifications to the
package.json
- I tried adjusting the
tsconfig.json
- I exported the
type
andinterface
from the filesrc/types/locationTypes.ts
Location Types (locationTypes.ts)
// Defining TypeScript Type for Latitude
export type TLatitude = number;
// Defining TypeScript Type for Longitude
export type TLongitude = number;
// Defining TypeScript Interface for Coordinates
export interface ICoordinates {
latitude: TLatitude;
longitude: TLongitude;
}
Main Entry Point (index.ts)
// Importing TypeScript Types
import * as dateTypes from './types/dateTypes';
import * as locationTypes from './types/locationTypes';
// Exporting Modules
export {
dateTypes,
locationTypes,
};
Package Configuration (package.json)
{
"name": "@username/custom-types",
"version": "1.0.0",
"main": "./dist/index.ts",
"types": "./dist/index.d.ts",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/username/custom-types.git"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/username"
},
"author": "Jeff Lewis",
"license": "MIT",
"keywords": [
"typescript",
"types",
"component-library",
],
"scripts": {
"build": "cd src && tsc && cp ../package.json && Echo Build completed!",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"devDependencies": {
"eslint": "^7.29.0",
"typescript": "^4.3.4"
}
}
TypeScript Configuration (tsconfig.json)
{
"include": ["src/*"],
"exclude": [
"**/__tests__/*",
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js",
],
"compilerOptions": {
"module": "ES6",
"outDir": "./dist",
"declaration": true,
"emitDeclarationOnly": true,
"typeRoots": ["./node_modules/@types", "./dist/index.d.ts"],
"strict": true,
"strictFunctionTypes": true,
}
}