2

I created a TS library that builds to dist as follows:

dist/
  - main.js
  - main.d.ts
  - tools.js
  - tools.d.ts
src/
  - main.ts
  - tools.ts

And my package.json is defined as follows:

"name": "@ws/my-lib"
"exports": {
  "./main": "./dist/main.js",
  "./tools": "./dist/tools.js"
},
"typesVersions": {
  "*": {
    "main": ["./dist/main.d.ts"],
    "tools": ["./dist/tools.d.ts"]
  }
}

However my CRA app fails to import any of my libs:

import { aFunction } from '@ws/my-lib/tools'

Module not found: Can't resolve '@ws/my-lib/tools' in '/path/to/component/component'

What is the correct way to do this?

1 Answer 1

3

You will need to specify the TS versions with the typesVersions field in package.json. See code below:

{
    "name": "@ws/my-lib"
    "exports": {
        "./main": "./dist/main.js",
        "./tools": "./dist/tools.js"
    },
    "typesVersions": {
        ">=4.1": { // put your desired ts version here
            "*": {
                "main": ["./dist/main.d.ts"],
                "tools": ["./dist/tools.d.ts"]
            }
        }
    }
}

check this document for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.