ng2-pdf-viewer icon indicating copy to clipboard operation
ng2-pdf-viewer copied to clipboard

Dynamic import cannot be analyzed by Vite

Open tehdb opened this issue 1 year ago • 14 comments

On angular's dev-server start getting the following warning in the console:

Watch mode enabled. Watching for file changes...
NOTE: Raw file sizes do not reflect development server per-request transformations.
  ➜  Local:   http://localhost:4200/
  ➜  press h + enter to show help
10:22:02 AM [vite] warning:
.../src/frontend/.angular/cache/18.2.2/vite/deps/ng2-pdf-viewer.js
11940|        const worker = yield import(
11941|          /*webpackIgnore: true*/
11942|          this.workerSrc
   |          ^^^^^^^^^^^^^^
11943|        );
11944|        return worker.WorkerMessageHandler;
The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

  Plugin: vite:import-analysis
  File: .../src/frontend/.angular/cache/18.2.2/vite/deps/ng2-pdf-viewer.js?v=c66f4614
10:22:02 AM [vite] warning:
.../src/frontend/.angular/cache/18.2.2/vite/deps/ng2-pdf-viewer.js
25819|        const sandbox = import(
25820|          /*webpackIgnore: true*/
25821|          sandboxBundleSrc
   |          ^^^^^^^^^^^^^^^^
25822|        );
25823|        sandbox.then((pdfjsSandbox) => {
The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

  Plugin: vite:import-analysis
  File: .../src/frontend/.angular/cache/18.2.2/vite/deps/ng2-pdf-viewer.js?v=c66f4614

rm -rf node-modules package-lock.json .angular && npm install did not help. Everything else seems to work fine, the production build completes without any warnings, and the PDF preview works as expected.

  • Angular 18.2.2
  • ng2-pdf-viewer 10.3.0
  • Node.js 20.16.0
  • MacOS 14.6.1

tehdb avatar Sep 02 '24 08:09 tehdb

same problem here... thks.

mateogo avatar Sep 05 '24 11:09 mateogo

I have the same issue. Wouldn't be possible to add /vite-ignore/ where there is /webpack-ignore/? This solves the issue

alfmosmq avatar Sep 10 '24 11:09 alfmosmq

relevant for this topic: https://github.com/mozilla/pdf.js/pull/18395

ng2-pdf-viewer can't do anything helpful here.

ftaffelt avatar Sep 10 '24 16:09 ftaffelt

It’s unfortunate that this error can’t be resolved at the moment. Does anyone have suggestions on how to instruct the compiler to safely ignore this issue?

Thanks in advance for any insights!

D-Abdi avatar Oct 18 '24 16:10 D-Abdi

This issue does not belong here, the error comes from pdfjs. See https://github.com/mozilla/pdf.js/issues/19077

This should be closed

shamoon avatar Dec 06 '24 07:12 shamoon

@tehdb - Just to confirm, while you get this error in the local dev server, you are not getting it in a production build? We just upgraded to Angular v.19 and started seeing this error...

joewIST avatar Dec 19 '24 16:12 joewIST

Also getting this error when upgraded to V18. So frustrating!!!!!

DeanWilliamMills avatar Jan 20 '25 14:01 DeanWilliamMills

Hi, I use "ng2-pdf-viewer": "9.1.0", with Angular 18.2.13, and I receive this error with vite:

Image

any update about this problems?

adilorenzodema avatar Feb 14 '25 15:02 adilorenzodema

I am using ng2-pdf-viewer: 10.0.0 and angular 19.1.17 and have same issue... Any other ideas?

fua03 avatar Mar 07 '25 16:03 fua03

The above dynamic import cannot be analyzed by Vite. See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

Plugin: vite:import-analysis File: /Users/darwinraj/Documents/SODISYS/Projects/sodisys-saas/projects/ng-sodisys/.angular/vite-root/sodisys/chunk-77QDKOY6.js

DarwinSODISYS avatar Mar 12 '25 18:03 DarwinSODISYS

You should close the duplicate issue you opened for this #1184, then you can refer back to my other comment https://github.com/VadimDez/ng2-pdf-viewer/issues/1130#issuecomment-2522293084 and research why this is not a bug to report here (aka, google it)

shamoon avatar Mar 12 '25 19:03 shamoon

This bug is not related to Firefox. On my side the bug appears after I run ng serve, I open Chrome and when I come back to the terminal I see the warning. I use angular 19.1.7 and tested with ng2-pdf-viewer v10.0.0 and 10.0.4

fua03 avatar Mar 14 '25 08:03 fua03

The issue was resolved in the newest version of pdfjs-dist (released 2 days ago). I created the following PR to update the version of the aforementioned lib in ng2-pdf-viewer: https://github.com/VadimDez/ng2-pdf-viewer/pull/1188

adel-haidar avatar Apr 01 '25 19:04 adel-haidar

2 months later and still no new release for the fix

fua03 avatar May 22 '25 07:05 fua03

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 29 '25 03:07 stale[bot]

Commenting so that this issue doesn't get closed for no valid reason

ldt-fweichert avatar Nov 05 '25 10:11 ldt-fweichert