preactjs / wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
https://wmr.dev/
MIT License
4.92k stars 109 forks source link

The requested module '/@npm/scheduler' does not provide an export named 'unstable_NormalPriority' #922

Closed Aloento closed 2 years ago

Aloento commented 2 years ago

Describe the bug

Uncaught SyntaxError: The requested module '/@npm/scheduler' does not provide an export named 'unstable_NormalPriority' (at react-context-selector:3:36)

from import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';
in \node_modules\@fluentui\react-context-selector\lib\createContext.js

unstable_NormalPriority from \node_modules\scheduler\cjs\scheduler.{Env}.js defined in \node_modules\@types\scheduler\index.d.ts

To Reproduce yarn create wmr & yarn add @fluentui/react-components

index.js

export function App() {
  return (
    <LocationProvider>
+      <FluentProvider theme={webLightTheme}>
        <div class="app">
          <Header />
          <ErrorBoundary>
            <Router>
              <Route path="/" component={Home} />
              <Route path="/about" component={About} />
              <Route default component={NotFound} />
            </Router>
          </ErrorBoundary>
        </div>
+      </FluentProvider>
    </LocationProvider>
  );
}
rschristian commented 2 years ago

Just want to add to this issue that adding @rollup/plugin-commonjs does make the error disappear for me, so it sounds like once we narrow that weird Rollup version bug down you should have a working solution to this.

For any other readers, you can do the following:

$ yarn add @rollup/plugin-commonjs

wmr.config.mjs

 import { defineConfig } from 'wmr';
+import commonjs from '@rollup/plugin-commonjs';

 // Full list of options: https://wmr.dev/docs/configuration
 export default defineConfig({
     /* Your configuration here */
     alias: {
         react: 'preact/compat',
         'react-dom': 'preact/compat'
     },
+    plugins: [commonjs()]
 });

Edit: Doesn't work in dev, so not a solution.

developit commented 2 years ago

@Aloento there's no need to create a new issue for each broken package - they're all the same issue: WMR doesn't support conditional re-exports in CommonJS modules. This affects all packages published by the React team, and a number of packages from the React community that have copied their packaging design.