I am dealing with a small package that contains a package.json
file structured as follows:
{
"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": ""
}
The TypeScript configuration in my exported package and the application importing it looks like this (excluding the declaration
field which is only present in the exported package):
{
"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"],
}
I am struggling to determine the correct configuration for the main
and types
fields in the package.json
.
When my app attempts to do import @nomatter/utils
, the TypeScript compiler raises an error stating that it cannot resolve the import.
I expected the TSC compiler to be able to read the imported js
files generated by itself. However, when I examine out-tsc/src/index.js
, it appears to have the basic export
statement that I anticipated based on the provided configurations. I am unsure why it cannot be located?
https://i.sstatic.net/D6QQQ.png
index.ts
simply contains export const signupSchema = {};
, while index.d.ts
consists of
export declare const signupSchema: {};