huozhi / sugar-high

✏️ Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped
https://sugar-high.vercel.app
539 stars 17 forks source link

Unable to resolve sugar-high module after installing with pnpm #88

Closed nembal closed 10 months ago

nembal commented 10 months ago

I recently switched my project from npm to pnpm. After the switch, I (re)installed sugar-high using the pnpm add sugar-highcommand. The library was successfully added to the node_modules folder. However, when I tried to import and use the highlight function from sugar-high, the module could not be resolved.

As a temporary workaround, I've removed syntax highlighting from my project. However, having syntax highlighting working would be ideal.

Steps to Reproduce:

  1. Switch the project from npm to pnpm (the node_module folder first get deleted then pnpm i
  2. Install sugar-high using pnpm add sugar-high.
  3. Try to import the highlight function from sugar-high.

Expected Behavior:

The sugar-high module should be resolved and the highlight function should be imported successfully.

Actual Behavior:

The sugar-high module could not be resolved, resulting in a build failure.

Error Message: Type error: Cannot find module 'sugar-high' or its corresponding type declarations.

 3 | import { MDXRemote } from 'next-mdx-remote/rsc';
  4 | import { TweetComponent } from './tweet';
> 5 | import { highlight } from "sugar-high";
    |                           ^
  6 | import React from 'react';
  7 |
  8 | function Table({ data }) {
 ELIFECYCLE  Command failed with exit code 1.

Environment:

Additional Context:

Is there a specific way to resolve this issue with pnpm? Any help would be greatly appreciated.

Thank you!

huozhi commented 10 months ago

Hi can you provide a reproduction that can let me to investigate? Thanks

lordkerwin commented 10 months ago

Same issue here, private corporate repo, so can't provide code example.

but using pnpm and get this.

2023-12-05 at 12 55 04

huozhi commented 10 months ago

I published a new patch 0.5.6 for typing fix, should be good now. Can you upgrade to see if it's fixed?

I feel you're using "moduleResolution": "node" in tsconfig.json if y'all can confirm. Using value "moduleResolution": "bundler" should also work without upgrade.

nembal commented 10 months ago

Magic. It builds now, thanks a lot.

I tested it without updating the package, and it was enough to change to "moduleResolution": from "node" to "bundler"

Thanks a lot

huozhi commented 10 months ago

@nembal good to hear that, does 0.5.6 also work for you without chaging moduleResolution?