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

Uncaught SyntaxError: The requested module '/node_modules/prop-types/index.js?v=cf7fa801' does not provide an export named 'default #249

Closed
7 tasks done
322332 opened this issue Nov 1, 2023 · 3 comments

Comments

@322332
Copy link

322332 commented Nov 1, 2023

Describe the bug

Hello, I have an npm library called platform. In this library, I have route structures and menus that I designed with my material UI library https://github.com/322332/platform. I want to install and use this library in other projects with npm, but when I add some material UI components, I get errors like ncaught SyntaxError: The requested module '/node_modules/prop-types/index.js?v=cf7fa801' does not provide an export named 'default' (at elementAcceptingRef.js?v=cf7fa801:1:8)

This error only comes in npm run dev.

npm run build and later
If I do npm run preview, I can build and use it without any problems.

npm package and github repo
https://github.com/322332/platform
https://www.npmjs.com/package/nuc-platform-vite

Reproduction

https://codesandbox.io/p/github/322332/platform-tester/main?import=true&layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clod2c9s20007356iru9eywmx%2522%252C%2522sizes%2522%253A%255B62.414664981036665%252C37.585335018963335%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clod2c9s20003356iyyyeyxgp%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clod2c9s20005356idzbjdcls%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clod2c9s20006356ipfr6a24l%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B60%252C40%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clod2c9s20003356iyyyeyxgp%2522%253A%257B%2522id%2522%253A%2522clod2c9s20003356iyyyeyxgp%2522%252C%2522activeTabId%2522%253A%2522clod2l8o401ck356idvx7ra7m%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clod2c9s10002356ivvce2k3r%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252F.gitignore%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fsrc%252Fapp.jsx%2522%252C%2522id%2522%253A%2522clod2l8o401ck356idvx7ra7m%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fsrc%252Fmain.jsx%2522%252C%2522id%2522%253A%2522clofxkb0o00vi356iy76oxlab%2522%252C%2522mode%2522%253A%2522temporary%2522%257D%255D%257D%252C%2522clod2c9s20006356ipfr6a24l%2522%253A%257B%2522id%2522%253A%2522clod2c9s20006356ipfr6a24l%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A5173%252C%2522id%2522%253A%2522clod4gbj100fv356iygjzyfd1%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clod4gbj100fv356iygjzyfd1%2522%257D%252C%2522clod2c9s20005356idzbjdcls%2522%253A%257B%2522id%2522%253A%2522clod2c9s20005356idzbjdcls%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522id%2522%253A%2522clod48a1t0050356ir73zuqml%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clod48a1t0050356ir73zuqml%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Steps to reproduce

No response

System Info

windows 11, chrome

Used Package Manager

npm

Logs

vite

Validations

@322332 322332 changed the title GET http://localhost:5173/node_modules/@mui/icons-material/esm/AdUnits.js?v=b26365ed net::ERR_BLOCKED_BY_CLIENT Uncaught SyntaxError: The requested module '/node_modules/prop-types/index.js?v=cf7fa801' does not provide an export named 'default Nov 1, 2023
@ArnaudBarre
Copy link
Member

So this issue is that @mui/icons-material is not bundled by the optmizer. I don't know if this is a bug in the optimizer or not? @patak-dev @bluwy

Using

  optimizeDeps: {
    include: ['@mui/icons-material'],
  },

allow @mui/icons-material to be bundled and fixes the issue (because non bundled deps need to be ESM otherwise)

BUT

Not using scoped imports for @mui/icons-material means that your bundle will contains EVERY icon, this is really bad.

@bluwy
Copy link
Member

bluwy commented Nov 2, 2023

Seems like vitejs/vite#3910. Not a dedupe issue exactly, but the same cause where the library publishes raw JSX files, Vite tells esbuild to externalize them, and consequently the JSX file that imports @mui/icons-material never got optimized together.

I'm not really sure if this is a common setup though. And usually you'd compile the JSX to JS before publishing the library.

@ArnaudBarre
Copy link
Member

Ok thanks, closing here as this might be a missing feature in core and not a bug in this plugin.
While publishing jsx/ts/tsx is allowed for use in internal libs, we don't ensure that you get all the features and this should be used only for people that knows the trade-off of publishing non standard JS files.
Just in case: The pattern of UI lib imported by multiple apps works very well in Vite with a mono-repo setup, you will even get HMR for the UI components!

@ArnaudBarre ArnaudBarre closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants