lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: Importing "@lexical/react" via vite occurs `Failed to resolve entry for package "@lexical/react"`

Open minamorl opened this issue 2 years ago • 8 comments

Lexical version: 0.11.1

Updated: 2023-06-26 See the comment I attached below

Steps To Reproduce

  1. set up vite project
  2. install the latest @lexical/react with others
  3. import { ... } from "@lexical/react"

This seems really strange for me. I thought package is broken but i couldn't find anything from the codebase. Context: I am trying to provide a rich text editor for general users who are not familiar with Lexical. I attached my github repo. package.json is just for lexical. npm run install and npm run dev on my repo

Link to code example: https://github.com/trishulaorg/veil

The current behavior

got

  ✘ [ERROR] Failed to resolve entry for package "@lexical/react". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-scan]

The expected behavior

Should be imported

minamorl avatar Jun 25 '23 18:06 minamorl

I figured out this was because of there's no index.js. Is it intentional? Me personally think it is better for users to provide index file IMHO

minamorl avatar Jun 25 '23 19:06 minamorl

I think we can add an index file in @lexical/react

acywatson avatar Jun 27 '23 21:06 acywatson

@acywatson If you need my help let me know. I think I can take handle of it when I'm available.

minamorl avatar Jun 28 '23 16:06 minamorl

In case someone's app won't have tree shaking, they'll end up having every single @lexical/react plugin bundled. Is there any issues with explicitly importing plugins like @lexical/react/LexicalListPlugin?

fantactuka avatar Jun 30 '23 15:06 fantactuka

In case someone's app won't have tree shaking, they'll end up having every single @lexical/react plugin bundled. Is there any issues with explicitly importing plugins like @lexical/react/LexicalListPlugin?

I don't think this should be an issue. AFAIK every modern toolchain is supporting treeshaking and even our own packages (at least every one except react) is structured in the same way with this expectation in mind.

I think there is no reason we can't do both though, right?

acywatson avatar Jun 30 '23 15:06 acywatson

Experiencing the same issue

ERROR in dll renderer renderer[11]
Module not found: Error: Can't resolve '@lexical/react' in .....

abhinavshm95 avatar Aug 21 '23 10:08 abhinavshm95

Same here

wspringer avatar Apr 19 '24 12:04 wspringer

Adding resolve.alias for @ to your vite.config solved the issue for me. FYI @wspringer

import { defineConfig } from "vite";
import path from "path";

export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
});

@minamorl @acywatson first of all - a wonderful work. I was curious if there is any update on this topic.

jasekt avatar Apr 22 '24 09:04 jasekt