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

Unexpected token for dynamic import nested in Promise.all #1563

Closed
2 of 3 tasks
DreierF opened this issue Jan 16, 2021 · 0 comments
Closed
2 of 3 tasks

Unexpected token for dynamic import nested in Promise.all #1563

DreierF opened this issue Jan 16, 2021 · 0 comments

Comments

@DreierF
Copy link
Contributor

DreierF commented Jan 16, 2021

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

Production build fails to compile the following code snippet:

async function loadThreeJsLibrary() {
    [THREE] = await Promise.all([
      import('three')
      // More import(...)
    ]);
    // Do something with THREE
}

void loadThreeJsLibrary();

Error:

$ vite build
building for production...
Unexpected token
file: /.../vite-project/main.js:10:6
 8: async function loadThreeJsLibrary() {
 9:     [THREE] = await Promise.all([
10:       import('three')
          ^
11:       // More import(...)
12:     ]);
error during build:
Error: Unexpected token
    at error (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:5265:30)
    at Module.error (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:9859:16)
    at tryParse (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:9740:23)
    at Module.setSource (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:10166:19)
    at ModuleLoader.addModuleSource (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:18336:20)
    at async ModuleLoader.fetchModule (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:18392:9)
    at async Promise.all (index 1)
    at async ModuleLoader.fetchStaticDependencies (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:18417:34)
    at async Promise.all (index 0)
    at async ModuleLoader.fetchModule (/.../vite-project/node_modules/rollup/dist/shared/rollup.js:18394:9)

Reproduction

Just add the three package to an empty vanilla vite project and add the lines from above to main.js. Then run yarn build.

Workaround

The build works when extracting the import('three') into a local variable or removing the Promise.all. Since this is just a single occurrence in our code this is not a big issue, but AFAICS this is perfectly valid JS code so it should also compile.

System Info

  • vite version: 2.0.0-beta.30
  • Operating System: MacOS
  • Node version: 14.15.4
  • Package manager (npm/yarn/pnpm) and version: yarn
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
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

1 participant