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

pdfjs-dist npm update from 2.0.489 to 2.0.943 causes webpack error: Can't resolve 'babel-runtime/regenerator' #10280

Closed
Jaans opened this issue Nov 21, 2018 · 8 comments

Comments

@Jaans
Copy link

Jaans commented Nov 21, 2018

After updating our npm package for pdfjs-dist from 2.0.489 to 2.0.943, webpack fails to build.
If we downgrade back to version 2.0.489 all is well again and the errors go away.

Here's a copy of the webpack build log showing the failures:

 10% building 1/1 modules 0 activei 「wds」: Project is running at http://localhost:8081/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\xxxxxx\Website\dist                                                                                                                                                                                                                                                                                                                                                         × 「wdm」:    2471 modules
ERROR in ./node_modules/pdfjs-dist/lib/core/pdf_manager.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\core'

ERROR in ./node_modules/pdfjs-dist/lib/core/evaluator.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\core'

ERROR in ./node_modules/pdfjs-dist/lib/core/obj.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\core'

ERROR in ./node_modules/pdfjs-dist/lib/display/fetch_stream.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\display'

ERROR in ./node_modules/pdfjs-dist/lib/display/network.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\display'

ERROR in ./node_modules/pdfjs-dist/lib/display/node_stream.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\display'

ERROR in ./node_modules/pdfjs-dist/lib/display/transport_stream.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\display'

ERROR in ./node_modules/pdfjs-dist/lib/shared/message_handler.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\shared'

ERROR in ./node_modules/pdfjs-dist/lib/web/ui_utils.js
Module not found: Error: Can't resolve 'babel-runtime/regenerator' in 'C:\xxxxxx\Website\node_modules\pdfjs-dist\lib\web'
i 「wdm」: Failed to compile.

Configuration:

  • Chrome: latest
  • Windows 10 Professional: Latest updates
  • PDF.js version: 2.0.943
  • Is a browser extension: No

What is the expected behavior? (add screenshot)
For the webpack build to succeed.

What went wrong? (add screenshot)
The webpack build fails, citing errors in the pdfjs-dist npm package for:
Module not found: Error: Can't resolve 'babel-runtime/regenerator'

Package.json excerpt follows:

{
 ...
 "engines": {
    "node": ">= 8.9.0"
  },
  "private": true,
  "devDependencies": {
    "@babel/core": "^7.1.6",
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/preset-env": "^7.1.6",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.4",
    "clean-webpack-plugin": "^1.0.0",
    "copy-webpack-plugin": "^4.6.0",
    "css-loader": "^1.0.1",
    "eslint": "^5.9.0",
    "file-loader": "^2.0.0",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "http-server": "^0.11.1",
    "less": "^3.8.1",
    "less-loader": "^4.1.0",
    "mini-css-extract-plugin": "^0.4.4",
    "optimize-css-assets-webpack-plugin": "^5.0.1",
    "style-loader": "^0.23.1",
    "webpack": "^4.26.0",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.10"
  },
  "dependencies": {
    "@babel/polyfill": "^7.0.0",
    "bootstrap": "^3.3.7",
    "font-awesome": "^4.7.0",
    "jquery": "^3.3.1",
    "jquery-ui": "^1.12.1",
    "moment": "^2.22.2",
    "pdfjs-dist": "^2.0.943",
    "popper.js": "^1.14.5",
    "uuid": "^3.3.2",
    "whatwg-fetch": "^3.0.0"
  }
}
@Jaans
Copy link
Author

Jaans commented Nov 21, 2018

Coincidentally, version 2.0.550 works fine and does not give webpack build errors.

@timvandermeij
Copy link
Contributor

I think this is because babel-runtime/regenerator is necessary for supporting the async/await syntax with Babel; refer to 099ed08#diff-b9e12334e9eafd8341a6107dd98510c9R185. It looks like the problem is that we require Babel 6 (refer to https://github.com/mozilla/pdf.js/blob/master/package.json#L7) whereas in your package.json you're requiring Babel 7, which may lead to a conflict. This could perhaps be resolved by us upgrading to Babel 7, but that is already tracked in #10229 for a different reason, so we can close this.

@wojtekmaj
Copy link
Contributor

@timvandermeij Babel 6 or 7, doesn't really matter. If your code requires something, it should have it listed as a dependency. As such, I consider all currently released versions as faulty in that matter, and I suggest to add @babel/runtime as a dependency of pdfjs-dist. Another idea is to get rid of @babel/runtime dependency (probably the best approach).
May you consider reopening this?

@Snuffleupagus
Copy link
Collaborator

None of this will be a problem if you actually use the pre-built library; please see the files distributed in https://github.com/mozilla/pdfjs-dist/tree/master/build respectively in https://github.com/mozilla/pdfjs-dist/tree/master/web, which are officially supported and won't suffer from the issues described here.

@wojtekmaj
Copy link
Contributor

Ah, I see. I was importing PDFLinkService which does not belong to the main lib. Thanks a bunch!

@Jaans
Copy link
Author

Jaans commented Feb 3, 2019

I'm a little confused. The versions at https://github.com/mozilla/pdfjs-dist/tree/master/build and https://github.com/mozilla/pdfjs-dist/tree/master/web are still version 2.0.489 at the time of this writing and this version is devoid from the issue I was reporting here.

Assuming @Snuffleupagus means that we should be using the pdfjs-dist version over pdfjs then I'm confused even more because the npm package for pdfjs-dist is at version 2.0.943 which has the issue (see https://www.npmjs.com/package/pdfjs-dist)

We are needing to pin the pdfjs-dist npm package at "2.0.550" as anything more recent breaks.

Am I missing something?

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Feb 3, 2019

The versions at https://github.com/mozilla/pdfjs-dist/tree/master/build and https://github.com/mozilla/pdfjs-dist/tree/master/web are still version 2.0.489 at the time of this writing and this version is devoid from the issue I was reporting here.

See https://github.com/mozilla/pdfjs-dist/releases for the latest version, the other problem described here (non-updating master branch) is being tracked in issue #10391.

Assuming @Snuffleupagus means that we should be using the pdfjs-dist version over pdfjs

That's not what #10280 (comment) implies; rather it just points out that if you are using https://github.com/mozilla/pdfjs-dist, then you should (in general) use the files found in the build and web folders (and not the ones in the lib folder).

@Jaans
Copy link
Author

Jaans commented Feb 4, 2019

That actually helps. Thanks for clearing up.

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

4 participants