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

require('../build/pdf.js') not working #12

Open
bastienmoulia opened this issue Mar 16, 2017 · 5 comments
Open

require('../build/pdf.js') not working #12

bastienmoulia opened this issue Mar 16, 2017 · 5 comments

Comments

@bastienmoulia
Copy link

I got an error on pdfjsLib = require('../build/pdf.js'); (https://github.com/legalthings/pdf.js-viewer/blob/master/pdf.js#L12062)

Indeed there is no more build folder, maybe a patch for pdf.js is missing.

@brandondrew
Copy link
Contributor

I ran into this too. The problem seems to be that pdf.js is assuming that nothing else is using require, and so it is branching on the presence or absence of require, based on the assumption that nothing else could have caused require to be present.

I have a very hacky solution, not remotely suitable for PR, but perhaps looking at the code that worked in my case might help you solve it for yours, and might lead to a general solution for everyone getting adopted for this project. I simply wrap the failing line in a try block, and recover by doing what is (in my case) the right thing:

  if (typeof require === 'function') {
   try {
    pdfjsLib = require('../build/pdf.js');
   }
   // when require fails, we do the right thing
   catch(e) {
    pdfjsLib = window['pdfjs-dist/build/pdf'];
   }
  } else {
   pdfjsLib = window['pdfjs-dist/build/pdf'];
  }

@pdemilly
Copy link

pdemilly commented May 1, 2017

I am using webpack and having the same error. It seems to me that this part of code is trying to load pdfjs-dist pdf.js file. Does it need to be loaded first. if so would it not be something lke

require ('pdfjs-dist/build/pdf.js')
better suited?

@moesjarraf
Copy link
Member

moesjarraf commented May 2, 2017

This issue is known in the mozilla repo and has been fixed in the newer version of mozilla/pdf.js by changing the order of require. We have to upgrade our fork of pdfjs and then upgrade the source of pdf.js-viewer based on the fork.

The thing is, there hasn't been a stable release after the fix was made by mozilla on 11th of march. I recommend only upgrading the source after they create a new Latest release, so we can be sure that the release has no new undiscovered bugs. The current latest release i see is v1.7.225 from jan 26th.

@netzwerkwelten
Copy link

Will this issue be fixed next time?

@PLQin
Copy link

PLQin commented Jul 14, 2021

edit webpack config or vue.config.js

config.module.rules.push({
    test: /\.pdf$/,
    use: {
        loader: 'file-loader',
        options: {
            name: '[path][name].[ext]',
        },
    },
});

// vue.config.js configureWebpack 中
config.module
    .rule('pdf')
    .test(/\.pdf$/)
    .use('pdf')
    .loader('file-loader')
    .end();

config.module
    .rule('pdf')
    .test(/\.pdf$/)
    .use('file-loader?name=[path][name].[ext]')
    .loader('file-loader')
    .end();

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

6 participants