lowlighter / libs

🍱 Collection of carefully crafted TypeScript standalone libraries. Minimal, unbloated, convenient.
https://jsr.io/@libs
MIT License
98 stars 11 forks source link

Where are the TS types for Node? #67

Open mabasic opened 2 months ago

mabasic commented 2 months ago

I am using the library in Node with Typescript, but don't see types.

    "@lowlighter/xml": "^5.4.7",

I have tried using

npx jsr add @lib/xml

but the command fails:

> npx jsr add @libs/xml
Setting up .npmrc...ok
Installing @libs/xml...
$ npm install @libs/xml@npm:@jsr/libs__xml
npm ERR! Cannot read properties of null (reading 'matches')
lowlighter commented 2 months ago

Yes it seems so

I'm not entirely sure why (I'm a bit rusted on node + TS ecosystem since I mainly use TS runtimes now) but after generating types declarations with tsc mod.ts --declaration --emitDeclarationOnly --target esnext --allowImportingTsExtensions --moduleResolution bundler to create mod.d.ts and referencing the "types": "mod.d.ts" field in package.json, it is still unable to refer back to types

However I noticed that sometimes deleting the node_modules and reinstalling deps seems to prevent the error you mentionned from occured, but I'm not sure exactly why

Siilwyn commented 1 month ago

If you bundle the .d.ts files and point to the types from the package.json it should work. E.g.

  "exports": {
    "import": {
      "types": "./src/core/main.d.mts",
      "default": "./src/core/main.mjs"
    },
  },

As a workaround you can use JSR @mabasic: First add @jsr:registry=https://npm.jsr.io to .npmrc and then install with npm install @jsr/libs__xml.

mabasic commented 1 month ago

The workaround does not work for me. I still get the same error:

> npm install @jsr/libs__xml
npm error Cannot read properties of null (reading 'matches')
Siilwyn commented 1 month ago

@mabasic did you edit .npmrc?

mabasic commented 1 month ago

@mabasic did you edit .npmrc?

Yes

mabasic commented 1 month ago

Got it now to work, forgot to use pnpm since that is what I use xd.

  1. Use pnpx jsr add @lib/xml - this will add the missing line about jsr to the .npmrc file and fail
  2. Then, use pnpm install @jsr/libs__xml

But still, I should be able to use @lowlighter/xml package from npm with types.

This whole process feels very hacky atm.