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

SyntaxError: Named export 'styled' not found. The requested module '@mui/material/styles/index.js' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using: #503

Open
EnterVPL opened this issue Mar 27, 2023 · 5 comments

Comments

@EnterVPL
Copy link

API Platform version(s) affected: '@api-platform/admin': ^3.4.3

Description
I trying run auth on admin but I got error:

Server Error
SyntaxError: Named export 'styled' not found. The requested module '@mui/material/styles/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@mui/material/styles/index.js';
const { styled } = pkg;

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
<unknown>
file:///srv/app/node_modules/.pnpm/@api-platform+admin@3.4.3_zula6vjvt3wdocc4mwcxqa6nzi/node_modules/@api-platform/admin/lib/layout/Error.js (15)
ModuleJob._instantiate
node:internal/modules/esm/module_job (124:21)
async ModuleJob.run
node:internal/modules/esm/module_job (190:5)

How to reproduce
I just using code from docs: https://api-platform.com/docs/admin/authentication-support/

Possible Solution
I don't now. Frontend has never been my strong suit

Additional Context
Using this:

import React from 'react';
import ReactDOM from 'react-dom';
import { HydraAdmin } from '@api-platform/admin';

const Admin = () => <HydraAdmin entrypoint="https://demo.api-platform.com" />;

ReactDOM.render(<Admin />, document.getElementById('root'));

I am getting exactly the same error.

I using official docker images: https://github.com/api-platform/api-platform

@ferriss
Copy link

ferriss commented Apr 20, 2023

After an update I've got exactly the same problem, any progress on this yet?
Did you manage to resolve @EnterVPL ?

@EnterVPL
Copy link
Author

@ferriss
I just downloaded other api platform demo and I replaced PWA. After this performance yet pnpm install and update

@KDederichs
Copy link

Same issue here, it happens after you install the react-admin dependency yourself to start customizing it...
@alanpoulain it would be neat if you could take a look at this.

@ltcmdrkeen
Copy link

In our case, we added the following patch to fix this issue until it is fixed in a new release:

  1. Create a file pwa/patches/@api-platform__admin@3.4.3.patch
  2. Paste the following patch content:
diff --git a/lib/layout/Error.js b/lib/layout/Error.js
index ff42479b1eb353c1e3e9fb118f2e340bbd5556fc..70f45adf58814e1d65a085b8a38725bb794e45af 100644
--- a/lib/layout/Error.js
+++ b/lib/layout/Error.js
@@ -11,8 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
 };
 import React from 'react';
 import { Title, useTranslate } from 'react-admin';
-import { Accordion, AccordionDetails, AccordionSummary, Box, Button, Typography, } from '@mui/material';
-import { styled } from '@mui/material/styles/index.js'; // eslint-disable-line import/extensions
+import { styled, Accordion, AccordionDetails, AccordionSummary, Box, Button, Typography, } from '@mui/material';
 import ExpandMoreIcon from '@mui/icons-material/ExpandMore.js'; // eslint-disable-line import/extensions
 import HistoryIcon from '@mui/icons-material/History.js'; // eslint-disable-line import/extensions
 import RefreshIcon from '@mui/icons-material/Refresh.js'; // eslint-disable-line import/extensions
  1. In your package.json, add the patch:

"pnpm": {
    "patchedDependencies": {
      "@api-platform/admin@3.4.3": "patches/@api-platform__admin@3.4.3.patch"
    }
  }
  1. run pnpm i again

@shanginn
Copy link

same issue, even tried uninstalling react-admin and mui/material, nothing helped except the @ltcmdrkeen method.
genius! I'm truly amazed with this ability to patch deps like this :)

veteran29 added a commit to stethome/web-examples that referenced this issue Aug 2, 2023
veteran29 added a commit to stethome/web-examples that referenced this issue Aug 8, 2023
* Add symfony/uid

* Clean up .idea/ for api-platform

* Move Kernel to Shared/

* Automatically configure src/Module/{ApiResource,Entity} folders

* Update API title

* Setup modular folder structure

* Add OrmProcessor

* Add unique AbstractUuidEntity uuid property

* Add simple user registration via API

* Refactor UserRegisterProcessor, add UserProvider

* Add GetCollection for UserModel

* Add makefile and test namespaces check script

* Refactor UserProvider, add filtering and pagination

* Add UserRegisterProcessorTest

* Add LexikJWTAuthenticationBundle

* Prefix api routes with /api/

* Configure security

* Test authentication, add UUID to JWT payload

* Add Exam entity

* Add StethoMeApiClient, save examination date

* Scaffold basic front end, registration UI

* Improve performance on Windows/Mac

* Add login support to admin panel

api-platform/admin#503 (comment)

* Fix ExamModel examinedAt name

* Add NextAuth authentication to /app

* Add custom layout for /app

* Store client API token in session

* Add exams pages

* Add navbar layout

* Redirect NextAuth routes to PWA container

They overlap with our /api/auth and customization does not seem to work so this is a bit of a workaround.

* Fetch client token in exam details view

* Add Media-API token endpoint

* Implement fetching Media-API token from external API

* Add mediaUrl to Media-API token output

* Finish implementation of exam screen

* Code format

* Fix PWA dockerfile build

* Fix Caddy build

https://dunglas.dev/2023/08/6x-faster-docker-builds-for-symfony-and-api-platform-projects/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants