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

[pdfjd-dist v4] Top-level await is not available #115

Closed
TxcA opened this issue May 28, 2024 · 7 comments
Closed

[pdfjd-dist v4] Top-level await is not available #115

TxcA opened this issue May 28, 2024 · 7 comments

Comments

@TxcA
Copy link

TxcA commented May 28, 2024

Link PR: Update pdfjs-dist to 4.2.67 #111
Link Release: https://github.com/TaTo30/vue-pdf/releases/tag/v1.10.0

error log:

> npx vite --port=4000

  VITE v5.2.11  ready in 765 ms

  ➜  Local:   http://localhost:4000/
  ➜  Network: http://192.168.14.195:4000/
  ➜  press h + enter to show help
[vite-plugin-static-copy] Collected 1 items.
X [ERROR] Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

    node_modules/pdfjs-dist/build/pdf.mjs:19764:53:
      19764 │ /******/ __webpack_exports__ = globalThis.pdfjsLib = await (globalThis.pdfjsLibPromise = __webpack_exports__);~~~~~

After upgrading to 1.10.0, the use of top await in pdfjs-dist v4+ caused compilation errors on my end. I tried downgrading to 1.9.7, which resolved the issue. Then, I used the @tato30/vue-pdf@1.10.0 + vite-plugin-top-level-await plugin to fix the error.

I submitted this issue in order to alert other users about how to resolve this problem.

@EiuaLee
Copy link

EiuaLee commented May 29, 2024

npm install vite-plugin-top-level-await -D

@kingcwt
Copy link

kingcwt commented May 29, 2024

vite 配置 optimizeDeps: { esbuildOptions: { target: 'esnext', }, },

@lhiro
Copy link

lhiro commented May 29, 2024

try this

optimizeDeps: {
        include: ['pdfjs-dist'], // optionally specify dependency name
        esbuildOptions: {
            supported: {
                'top-level-await': true,
            },
        },
    },

@emargareten
Copy link

this is an issue with pdfjs and esbuild
mozilla/pdf.js#17245
evanw/esbuild#253

@TxcA
Copy link
Author

TxcA commented Jun 5, 2024

try this

optimizeDeps: {
        include: ['pdfjs-dist'], // optionally specify dependency name
        esbuildOptions: {
            supported: {
                'top-level-await': true,
            },
        },
    },

This method works during development, but yarn build still throws an error. Currently, we are still using the vite-plugin-top-level-await plugin to resolve this issue.

 ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

@lhiro Thanks~

@kuoruan
Copy link

kuoruan commented Jun 5, 2024

try this

optimizeDeps: {
        include: ['pdfjs-dist'], // optionally specify dependency name
        esbuildOptions: {
            supported: {
                'top-level-await': true,
            },
        },
    },

This method works during development, but yarn build still throws an error. Currently, we are still using the vite-plugin-top-level-await plugin to resolve this issue.

 ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

@lhiro Thanks~

Try this, it's not recommend to change the build target, we just add top-level-await to support list

optimizeDeps: {
  esbuildOptions: {
    supported: {
      'top-level-await': true,
    },
  },
},
esbuild: {
  supported: {
    'top-level-await': true,
  },
},

@TxcA
Copy link
Author

TxcA commented Jun 5, 2024

try this

optimizeDeps: {
        include: ['pdfjs-dist'], // optionally specify dependency name
        esbuildOptions: {
            supported: {
                'top-level-await': true,
            },
        },
    },

This method works during development, but still throws an error. Currently, we are still using the vite-plugin-top-level-await plugin to resolve this issue.yarn build

 ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

@lhiro Thanks~

Try this, it's not recommend to change the build target, we just add to support listtop-level-await

optimizeDeps: {
  esbuildOptions: {
    supported: {
      'top-level-await': true,
    },
  },
},
esbuild: {
  supported: {
    'top-level-await': true,
  },
},

🎉 @lhiro Thank you. After removing the vite-plugin-top-level-await plugin, I am now also able to run and build successfully.

@TaTo30 TaTo30 closed this as completed Jun 28, 2024
@TaTo30 TaTo30 mentioned this issue Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants