astoilkov / main-thread-scheduling

Fast and consistently responsive apps using a single function call
MIT License
1.29k stars 32 forks source link

Error when building a project with Vite #12

Closed mthh closed 9 months ago

mthh commented 9 months ago

Hi and thanks for your work on this library !

Since version 11.0.0 (i.e. with versions 11.0.0 and 12.0.0) I have encountered problems when I compile a project with Vite (5.0.x) that uses "main-thread-scheduling".

The compilation fails with the following message and Vite stops :

✘ [ERROR] Could not resolve "./src/utils/queueTask"

    node_modules/main-thread-scheduling/index.js:7:37:
      7 │ export { default as queueTask } from './src/utils/queueTask';
        ╵                                      ~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./src/utils/withResolvers"

    node_modules/main-thread-scheduling/index.js:8:41:
      8 │ export { default as withResolvers } from './src/utils/withResolvers';
        ╵                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./src/utils/requestAfterFrame"

    node_modules/main-thread-scheduling/index.js:9:38:
      9 │ export { default as afterFrame } from './src/utils/requestAfterFrame';
        ╵                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./utils/hasValidContext"

    node_modules/main-thread-scheduling/src/isTimeToYield.js:2:28:
      2 │ import hasValidContext from './utils/hasValidContext';
        ╵                             ~~~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./utils/queueTask"

    node_modules/main-thread-scheduling/src/yieldControl.js:2:22:
      2 │ import queueTask from './utils/queueTask';
        ╵                       ~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./utils/hasValidContext"

    node_modules/main-thread-scheduling/src/yieldControl.js:4:28:
      4 │ import hasValidContext from './utils/hasValidContext';
        ╵                             ~~~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./utils/promiseEscape"

    node_modules/main-thread-scheduling/src/yieldControl.js:5:58:
      5 │ ...PromiseEscape, requestPromiseEscape } from './utils/promiseEscape';
        ╵                                               ~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./tasks/createTask"

    node_modules/main-thread-scheduling/src/yieldControl.js:6:23:
      6 │ import createTask from './tasks/createTask';
        ╵                        ~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./tasks/removeTask"

    node_modules/main-thread-scheduling/src/yieldControl.js:7:23:
      7 │ import removeTask from './tasks/removeTask';
        ╵                        ~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./tasks/nextTask"

    node_modules/main-thread-scheduling/src/yieldControl.js:8:25:
      8 │ import { nextTask } from './tasks/nextTask';
        ╵                          ~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "./utils/withResolvers"

    node_modules/main-thread-scheduling/src/schedulingState.js:1:26:
      1 │ import withResolvers from './utils/withResolvers';
        ╵                           ~~~~~~~~~~~~~~~~~~~~~~~

Error: Build failed with 11 errors:
node_modules/main-thread-scheduling/index.js:7:37: ERROR: Could not resolve "./src/utils/queueTask"
node_modules/main-thread-scheduling/index.js:8:41: ERROR: Could not resolve "./src/utils/withResolvers"
node_modules/main-thread-scheduling/index.js:9:38: ERROR: Could not resolve "./src/utils/requestAfterFrame"
node_modules/main-thread-scheduling/src/isTimeToYield.js:2:28: ERROR: Could not resolve "./utils/hasValidContext"
node_modules/main-thread-scheduling/src/schedulingState.js:1:26: ERROR: Could not resolve "./utils/withResolvers"
...
    at failureErrorWithLog (/home/projects/vitejs-vite-adh7q9/node_modules/esbuild/lib/main.js:1641:15)
    at eval (/home/projects/vitejs-vite-adh7q9/node_modules/esbuild/lib/main.js:1049:25)
    at eval (/home/projects/vitejs-vite-adh7q9/node_modules/esbuild/lib/main.js:1517:9) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

It happens in a large project I'm working on but you can see a minimal repro here in a projet with only Vite, Typescript and main-thread-scheduling (this is a stackblitz project, hope this is fine to demonstrate the issue - try to change the main-thread-scheduling version to 10.0.0 in package.json to see it was working fine with older versions).

Am I doing something wrong or is there a workaround ? Thanks !

astoilkov commented 9 months ago

This is now fixed and released. Sorry for the inconvenience and thanks for reporting!

mthh commented 9 months ago

Thanks for the quick fix and the new release!