The design system package may experience difficulty loading material styles correctly

Our company is currently in the process of developing a design system that can be easily integrated into multiple projects as a package. While building the package has been successful, we encounter an error after installing it and trying to import the theme:

ERROR in ./node_modules/design-system/dist/esm/index.js 4:0-51
Module not found: Error: Can't resolve '@mui/material/styles' in '/Users/***/***/minimal-example/frontends/drupe-mo/node_modules/design-system/dist/esm'
Did you mean 'index.js'?
BREAKING CHANGE: The request '@mui/material/styles' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

To replicate the issue, I have created a small project which you can access here: https://github.com/antoniogamizbadger/minimal-example

To reproduce the problem, simply clone the project and follow these steps:

From the design-system directory:

npm ci
npm run build

From the package directory:

npm ci
# this is to avoid a symlink being created
rm -rf node_modules/design-system &&  npm install --install-links ../design-system

We have attempted various solutions, but are currently unsure of the root cause of this error. The error message provides some clues, but our attempts to resolve it have been unsuccessful. I previously asked a question on Stack Overflow here, but the suggested solution did not work in this case.

Note: We are using Rollup to build the design-system package, and importing components works without issues. The problem arises when importing the theme from the built package.

Any suggestions on what configuration changes we should make to resolve this issue?

Update

Changing the import statement from:

import { createTheme } from '@mui/material/styles';

to:

import { createTheme } from '@mui/material';

does not resolve the issue.

Answer №1

i needed to experiment with rollup plugins pipeline until I achieved the desired outcome while attempting to bundle custom MUI components.

references:

https://medium.com/@maayan_37411/how-to-create-a-react-multi-package-ui-library-2ba6ae0909b6

https://medium.com/@martin_hotell/typescript-library-tips-rollup-your-types-995153cc81c7

#######

including functional rollup.config.js (compatible with MUI) and tsconfig.json

//rollup.config.js
import commonjs   from "@rollup/plugin-commonjs";
import resolve    from "@rollup/plugin-node-resolve";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import typescript from "@rollup/plugin-typescript";
import postcss    from "rollup-plugin-postcss";
import url        from '@rollup/plugin-url'
import svgr       from '@svgr/rollup'
import dts        from 'rollup-plugin-dts'

import packageJson from "./package.json";

// eslint-disable-next-line import/no-anonymous-default-export
export default [{
  input: "./src/index.ts",
  output: [
    {
      file: packageJson.main,
      format: "cjs",
      sourcemap: true
    },
    {
      file: packageJson.module,
      format: "esm",
      sourcemap: true
    }
  ],
  plugins: [
    peerDepsExternal(),
    resolve(), 
    commonjs(), 
    typescript(),
    postcss(),
    url(),
    svgr(),
  ]
},
{
  input: './build/dts/index.d.ts',
  output: [{ file: 'build/index.d.ts', format: 'es' }],
  plugins: [dts()],
}
];

//tsconfig.json
{
  "compilerOptions": {
    "target": "es6",
    "lib": [
      "es6",
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "noImplicitAny": true,
    "noImplicitThis": true,
    "strictNullChecks": true ,

      // enabling declaration (.d.ts) emit
    "declaration": true,
    // optional - in general it's a good practice to decouple declaration files from your actual transpiled JavaScript files
   "declarationDir": "build/dts",
   // optional if you're using babel to transpile TS -> JS
   "emitDeclarationOnly": true
  },
  "include": [
    "src"
  ],
  "exclude": ["node_modules","build"]
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is spine.js truly capable of 'streamlining' POST requests?

I recently came across a post by Alex Maccaw, where he discusses the challenges of sending Ajax requests in parallel: Maccaw explains that if a user creates a record and quickly updates it, two Ajax requests are sent simultaneously - a POST and a PUT. How ...

Automatically Populate list upon webpage initialization - React, Redux, Firebase

A webpage I am working on consists of two main components: Categories and Items By utilizing the function initCategories() called within the componentDidMount() lifecycle method of Categories, I successfully display all categories on the screen. The initC ...

Analyze two objects and eliminate any duplicate keys present between them

I am currently conducting an experiment on objects where my goal is to remove keys from object1 that are present in object2. Here is an example of what I am trying to achieve: var original = { a: 1, b: 2, c: 3, e: { tester: 0, ...

When it comes to AFrame+Three.js, which is more efficient: having numerous meshes with minimal triangles per mesh or having a few meshes with a high number of

Currently working with Aframe 1.0.4 and Three.js 111, I am exploring the performance differences between: Whether it is better to have a few entities with a high number of triangles or many entities with fewer triangles each. Specifically, I am debating ...

Preserving the information from a webpage by utilizing casperjs for scraping and saving table data

What is the most efficient way to preserve table data collected during a web scraping process with casperjs? Saving it as a file after serializing into a json object. Sending an ajax request to php and then storing it in a mysql database. ...

Issue with CKEditor5 Link popup not displaying in both Bootstrap 5 modal and RSuite library modal in React

React: How to troubleshoot CKEditor5 Link popup not appearing in a modal using either Bootstrap 5 or rsuite library? Seeking advice on resolving this issue. Your help is appreciated! ...

Issue with React Material-UI where content is not visible when using full-screen Dialog

Upon reviewing the material-ui documentation (https://material-ui.com/components/dialogs/), it was noted that the dialog can be displayed in full screen mode. However, when attempting to integrate it with AppBar and ToolBar, the content within the DialogCo ...

Unable to designate decimal value as the default in DropdownListFor in ASP.NET Core when utilizing JavaScript

Everything appears to be functioning properly, except when dealing with decimal values in the following code snippet: $('select#listspec_0__qty option[value = 105.3]').attr("selected", true); ...

Angular data table is currently displaying an empty dataset with no information available

While attempting to display a data table in Angular JS, an issue arose where the table showed no available data despite there being 4 records present. Refer to the screenshot below for visual reference. https://i.sstatic.net/hdaW9.png This is the approac ...

Encountering the issue of "Cannot read properties of undefined" while attempting to pass data to a prop

Currently, I am developing a Vue application that heavily relies on charts. The issue lies in the fact that I am fetching data from the database individually for each chart component, resulting in multiple calls and a slower page load time. I am looking to ...

Tips for utilizing the Axios API client created using the OpenAPITools code generator

Currently, I am utilizing the Swagger/OpenAPI Codegen tool to automatically generate an API client for the Fetch client within my Vue application. However, I have decided that I would prefer to make use of Axios instead. To begin this transition, I initiat ...

Using MongoDB and NodeJS to retrieve data from a promise

When I make a request to the database using promises, my goal is to extract the values of "latitude" and "longitude" for all documents and store them in an array. This is how I am currently approaching it: const promises = [ dbo.collection("users").f ...

Extract the HTML table from Gmail and transfer it to Google Sheets with the help of Google Apps Script

Just dipping my toes into google apps script. On my to-do list is creating a script that can extract data from a table in Gmail and transfer it to Google Sheets. Here's an example of what the email body looks like: CONFIRMATION CODE GUEST&apo ...

Leveraging Vue properties within CSS styling

I am looking to utilize Vue data/prop variables within the <style> tag located at the bottom of my component. For example, suppose I have a component structured like this: <template> <div class="cl"></div> </template> < ...

What is the best way to display "SUCCESS" on the console when a launch is successful, and "ERROR" when it is unsuccessful?

Here is the question: I am delving into Node.js using the Puppeteer library, and I am looking to output "SUCCESS" in the console upon a successful execution, and "ERROR" if it fails. However, I am struggling to grasp how to achieve thi ...

Unexpected token in catch clause in React Native TypeScript

Despite having a fully configured React Native Typescript project that is functioning as expected, I have encountered a peculiar issue: Within all of my catch blocks, due to the strict mode being enabled, typescript errors are appearing like this one: htt ...

Is there a way to align the Material UI mobile menu to the left edge of the screen?

Need help with this UI issue: Currently working on designing a mobile web app using React and Material UI. I'm struggling to get the sidebar menu to start from the left edge of the screen, as it seems to have an unwanted margin preventing it. Any sug ...

Utilizing jQuery to implement a CSS style with a fading effect, such as FadeIn()

I have a jQuery script that applies a CSS style to an HTML table row when the user clicks on a row link: $(this).closest('tr').css("background-color", "silver"); Is there a way to soften this color change effect, such as by gradually fading in ...

How can you effectively filter out folders/files using the .npmignore feature?

After using Rollup to generate a lib folder for my npm package, I organized it with the following structure: /lib /components /stories To specify which files should be included in my package, I added the /lib folder to the whitelist in my package.json ...

The getServerSideProps function in Next.js is only executed once, meaning it won't retrieve fresh data when accessed via next/router

I'm working on a Next.js application with Server-Side Rendering (SSR) where I have an async function called getServerSideProps that is exported like this: export const getServerSideProps = getGenericServerSideProps([""]); The getGenericServerSideProp ...