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

Force node to use CJS to get around dependency import errors, and validate package types in CI #259

Merged
merged 3 commits into from
Aug 21, 2024

Commits on Aug 21, 2024

  1. Add commonjs type in package.json to be explicit

    Per recommendation from publint.  https://publint.dev/rules#use_type
    
    > The package does not specify the "type" field. NodeJS may attempt to detect the package type causing a small performance hit. Consider adding "type": "commonjs".
    sjdemartini committed Aug 21, 2024
    Configuration menu
    Copy the full SHA
    cf5d63d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6ad0cfd View commit details
    Browse the repository at this point in the history
  3. Force node to use CJS to get around dependency import errors

    Should resolve #256.
    
    Both `@mui/icons-material`
    (mui/material-ui#35233) and `lodash`
    (lodash/lodash#5107) have problems being
    imported in a consuming package when using ESM. The workarounds
    attempted in #258 almost
    seemed to work (didn't break a downstream bundled package using Vite),
    but still caused problems for the original example node application
    https://codesandbox.io/p/devbox/pensive-volhard-hyhtls, with errors
    like:
    
    ```
    Error: Cannot find module '/path/to/mui-tiptap-in-node/node_modules/@mui/icons-material/esm/FormatColorFill
    ```
    
    This approach is inspired by what tss-react does
    https://github.com/garronej/tss-react/blob/f5351e42e33f35f18415cfc1ffc6b08eb8ce4d25/package.json
    (e.g. see here
    garronej/tss-react@4699702
    and garronej/tss-react#164).
    
    With this change, this code now works in the node context (though
    slightly odd):
    
    ```
    import pkg from "mui-tiptap";
    const { FontSize, HeadingWithAnchor, ResizableImage, TableImproved } = pkg;
    ```
    sjdemartini committed Aug 21, 2024
    Configuration menu
    Copy the full SHA
    a49802a View commit details
    Browse the repository at this point in the history