Skip to content

import issue: Unable to resolve @import "~@fontsource/roboto" from xxx/node_modules/react-material-web/dist when using vite as bundler #1

@creamIcec

Description

@creamIcec

Me and my colleague can reproduce this issue by following steps below:

  1. create a new react app using vite as bundler by running command npm init vite@latest --template and choose react and typescript as scaffold;
  2. run npm install react-material-web (at the moment its version is 1.0.5);
  3. using the library components in project;
  4. when run npm run dev to start server, the error raised: Unable to resolve @import "~@fontsource/roboto" from xxx/node_modules/react-material-web/dist

A temporary solution would be removing the ~ symbol in the import statement at the 2nd line in /node_modules/react-material-web/dist/styles.css which means to turn
@import '~@fontsource/roboto';
into
@import '@fontsource/roboto';

After doing this little tweak it works.
I don't know if this is an issue related to vite bundler, but I think it's beneficial to first summit an issue here as it may affect some projects using vite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions