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
SyntaxError: Unexpected token '||=' #1041
Comments
So issue currently comes in, if you use a setup where you can not replace paths, e.g if you use SWC from nextjs then you can't really do that because you don't have the same webpack config capabilities. Seeing as this is a really common and recurring issue, would it not be worth implementing a prop to target different versions from pdfjs-dist instead? like add |
@paul-vd Can you create a minimum starter that uses SWC, so I can take a look? |
I'm also having this issue, same thing. I'm thinking in setting up an external webpack build to make a separate bundle and load it using an iframe. |
@ivanquirino Does this guide help you? |
I'm using NextJS 12, and I get this problem just by doing The problem appears in this file: I'm goint to look how to override module paths in nextjs |
@ivanquirino It is strange, because the official website uses NextJS 12 ( Its module.exports = withMDX({
// `/about` becomes `/about/index.html`
trailingSlash: true,
pageExtensions: ['js', 'jsx', 'tsx', 'mdx'],
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// To work with the latest version of pdfjs-dist
config.externals.push({
canvas: 'canvas',
});
return config;
},
}); |
@ivanquirino This settings might be useful to you. |
I am using Next 12.0.10
Thanks! Does this disable the SWC compiler? |
I don't try SWC yet. It is great if you can create a minimum/simple project with SWC enabled, so I can take a look to see if it is compatible. |
Next uses SWC for compiling by default from version 12, so the question is if that config is going to disable it and use webpack instead. |
I'm using the module alias, but still getting the same error, in the stack trace it still points to the same file as OP's image. |
Even though the config is in place, when react-pdf-viewer requires pdfjs-dist, it gets the default version: |
FWIW you're not alone, I've got a similar setup and are encountering the same issue as you even with the following config:
|
Vercel / AWS Lambda have now made Node.js v16 available which in my experience provides the ultimate fix for the issue here. I am not sure about the discussion around SWC here as my assumption was the fail was caused by using logical or assignment operator in the recent versions of |
following up on the source of this issue, updating to latest pdfjs-dist creates more syntax error issues, this time client side in older browsers as their bundle uses private field operators not working on Safari < 14.1 for example: |
Hi @paul-vd I solved this issue updating my NodeJS version I was using Node 14 and I found same error then I updated to Node 16 and now it's working fine. Regards |
Thanks for the info, will give it a try. |
regarding my earlier suggestion and some others here, you can totally get around the latest JS syntax and Node js version by simply importing the legacy version i. e. it's all documented as per earlier comment: in fact you should really take this approach as either the browser or node will always play a catch up game with latest js syntax which will always be in the non legacy |
I'm running into the following issue,
I suspect I should update the alias in webpack to point to the legacy version, but this is strange encountering such issues in a brand new project, eg nextjs.
The text was updated successfully, but these errors were encountered: