Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where are the TS types for Node? #67

Open
mabasic opened this issue Jun 24, 2024 · 6 comments
Open

Where are the TS types for Node? #67

mabasic opened this issue Jun 24, 2024 · 6 comments

Comments

@mabasic
Copy link

mabasic commented Jun 24, 2024

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
Copy link
Owner

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
Copy link

Siilwyn commented Jul 24, 2024

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
Copy link
Author

mabasic commented Jul 31, 2024

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
Copy link

Siilwyn commented Jul 31, 2024

@mabasic did you edit .npmrc?

@mabasic
Copy link
Author

mabasic commented Jul 31, 2024

@mabasic did you edit .npmrc?

Yes

@mabasic
Copy link
Author

mabasic commented Jul 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants