libs
libs copied to clipboard
Where are the TS types for Node?
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')
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
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.
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')
@mabasic did you edit .npmrc?
@mabasic did you edit .npmrc?
Yes
Got it now to work, forgot to use pnpm since that is what I use xd.
- Use
pnpx jsr add @lib/xml- this will add the missing line about jsr to the.npmrcfile and fail - 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.