caoxiemeihao / vite-plugins

🌱 为社区尽一份绵薄之力
MIT License
65 stars 15 forks source link

Question: Will the dynamic-imports plugin allow me to import packages that use dynamic imports? #16

Closed capndave closed 2 years ago

capndave commented 2 years ago

Will the dynamic-imports plugin allow me to import packages that use dynamic imports? If so, how do I set that up in my vite project?

Example of current problem

import { useState } from 'react'
import './App.css'
import { ComponentWithDynamicImports } from 'proprietary-component-library';

function App() {
  return (
    <div className="App">
      <ComponentWithDynamicImports />
    </div>
  )
}

export default App

returns

Failed to load resource: the server responded with a status of 504 (Gateway Timeout)
ypeError: Failed to fetch dynamically imported module: http://localhost:3000/node_modules/.vite/deps/someFile.js undefined
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'isProxied')
    at index-b15911fe.js:1:19822
    at l (index-b15911fe.js:1:1866)
    at Object.next (index-b15911fe.js:1:1157)
    at s (index-b15911fe.js:1:693)
caoxiemeihao commented 2 years ago

First of all, this package only fixes the path restriction of vite when using dynamic import. It is not responsible for loading modules.
Like this:

import('@alias/comp.tsx') -> import('./comp.tsx')
import('./' + 'comp.tsx') -> import('./comp.tsx')

Can I see the code of ComponentWithDynamicImports?
Another question: did your error report occur during vite build or vite serve?

capndave commented 2 years ago

Error was with vite serve. I don't have visibility into the component other than what appears in node_modules. I think those files might be minified as well.

caoxiemeihao commented 2 years ago

https://github.com/vite-plugin/vite-plugin-dynamic-import

capndave commented 2 years ago

Unfortunately I can't show the code of ComponentWithDynamicImports, as it's a stand-in for a proprietary component at my company. I'll spend some time digging into it when I can. It's occurring during vite serve.

On Wed, Apr 6, 2022 at 7:23 PM 草鞋没号 @.***> wrote:

First of all, this package only fixes the path restriction of vite when using dynamic import. It is not responsible for loading modules. Can I see the code of ComponentWithDynamicImports? Another question: did your error report occur during vite build or vite serve?

— Reply to this email directly, view it on GitHub https://github.com/caoxiemeihao/vite-plugins/issues/16#issuecomment-1090953755, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTOOZNM4CCG5AMV7FVVCUDVDYTHTANCNFSM5SW75AHA . You are receiving this because you authored the thread.Message ID: @.***>