SyntaxError: Unexpected token '||=' - javascript

I need to build nextjs project with PDFViewer using #react-pdf-viewer, but when collecting page there are some error SyntaxError: Unexpected token '||='.
The problem is occured from pdf.js in node_modules, I try to change ||= to || in pdf.js, and build no error.
But I need to deploy in hosting and need to download pdf.js from yarn install, some code that I change before will be restored.
How can I solve it?

This is great example how to correctly setup react-pdf with NextJS.
However, as mentioned in comments, you still get SyntaxError: Unexpected token '||=' with a node version below 15, so you need to upgrade to >=15.0.
Then it works as expected.

Related

Magento 2 cms backend javascript error Uncaught SyntaxError: Invalid or unexpected token

Suddenly I am having javascript error and cannot edit any cms page (cms/page/edit/page_id/45) or block. I have been trying to solve this for the past week with no success. I have also tried removing the modules that I have installed recently.
I did not touch any core files and I have updated file permissions but still get this error below in chrome console from the core static files
VM6148:68 Uncaught SyntaxError: Invalid or unexpected token
at template (template.js:79:36)
at render (template.js:140:24)
at iterate (template.js:236:33)
at Function._.each._.forEach (underscore.js:150:9)
at Object.template (template.js:206:15)
at UiClass.initConfig (class.js:89:28)
at UiClass._super (wrapper.js:106:35)
at UiClass.initConfig (abstract.js:123:18)
at UiClass.initConfig (wrapper.js:109:34)
at UiClass._super (wrapper.js:106:35)
Image showing spinner and javascript error
In my case, it was a database issue due to js injection. Patching a 3rd party extension fixed the issue.

SyntaxError: Unexpected token in JSON at position 0 in meteor

I am getting an error when running meteor.js. This is the following error:
PS C:\Users\ketan\Documents\Meteor> meteor run
C:\Users\ketan\AppData\Local\.meteor\packages\meteor-tool\2.1.1\mt-os.windows.x86_64\dev_bundle\lib\node_modules\meteor-promise\promise_server.js:218
throw error;
^
SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at ProjectContext._readResolverResultCache (C:\tools\project-context.js:605:16)
at ProjectContext.reset (C:\tools\project-context.js:245:10)
at new ProjectContext (C:\tools\project-context.js:60:8)
at Command.doRunCommand [as func] (C:\tools\cli\commands.js:356:24)
at C:\tools\cli\main.js:1528:15
I can't understand the error. Please tell me the solution for this.
Note: My laptop shut down in the previous session of the meteor.
The Solution
How I ultimately ended up fixing this was just by re-cloning the repository I was working on from GitHub - after this, my application ran fine.
NOTE: I've edited this answer because I originally thought Jankaput's answer worked for me, but after digging a little further I found that it didn't.
More Info
I ran into the same problem after a shutdown while a previous Meteor process was running.
For me, running meteor reset and re-installing node_modules seemed to prevent the mentioned error from happening, but when I ran the application, I noticed odd behavior from several different sections of the application (i.e. certain packages wouldn't work, some methods that normally run fine on startup threw errors, etc.)
This makes me think that some sort of project setting was corrupted due to the meteor server I was running ending abnormally when I force shut down my computer. I'm not sure why whatever setting was corrupted managed to stay that way across a meteor reset (since meteor --help specifies that it 'Resets the project state'), but the fact that a re-cloning work makes me think that it did.
Due to the fact that it seems like running meteor reset could allow some corrupted project settings to fly under the radar after this issue pops up, I personally feel that it's probably just best to re-clone your project if this happens to you, just to be sure that nothing about the project is corrupted.
This appears to me that you have a syntax error in a JSON file that is being read by the Meteor build tool. Do you have a settings.json file in use in your project? If so, check for trailing commas or keys missing double quotes as these are the most common errors introduced to a JSON file.

Unhandled JS Exception: Unexpected token '<' no stack

I started facing an issue with running my react native application in iOS device
Unhandled JS Exception: Unexpected Token '<' no stack
This started happening after i generated the main.jsbundle in react native application using the below curl command
curl http://localhost:8081/index.ios.bundle -o main.jsbundle
and added this file in xcode project. This seems to like an issue with parsing of the main.jsbundle file which i added in react-native.
Prior to the above process i tried running the application with localhost:8081 for finding the jsbundle but doesn't help me for ios devices. Code in my develop branch is working fine, but same develop code in my feature branch doesn't work with main.jsbundle.
Did anyone faced similar issue with running react native code in iOS devices.
The response you're getting is most likely in HTML format, which starts with a <. When you try to parse this response (presumably with res.json()) an exception is thrown, because a json string cannot start with a <
Try debugging your program and check exactly what the response you're getting is

Uncaught SyntaxError: Unexpected token ; after deploying to heroku in application.js

I have a rails app running Materialize css and it works just fine in development.
Right after I deploy to heroku I get a Uncaught SyntaxError: Unexpected token ; in the application.js file.
The line of code reads: parentNode,;null!==i&&!t(i).is(do..and I just can't find it in my assets.
Any help is appreciated
I'm not really sure what fixed it but here's what I did.
Cleared my cached assets.
Erased avery trace of bootstrap in my app.
Precompiled again and pushed to heroku.
It works fine now

Ember build error

When running ember build --environment=production everything seems to compile just fine. Putting the files inside dist/ on my server goes fine as well, but when I click a link on my page I get the following error:
vendor-ef159bc….js:11 Error while processing route: account Unexpected token < in JSON at position 0 SyntaxError: Unexpected token < in JSON at position 0
at Object.parse (native)
at ae.parseJSON (http://localhost:8000/assets/vendor-ef159bc608efff575c24c5e13c2d1218.js:3:12644)
at W (http://localhost:8000/assets/vendor-ef159bc608efff575c24c5e13c2d1218.js:1:15665)
at n (http://localhost:8000/assets/vendor-ef159bc608efff575c24c5e13c2d1218.js:3:13996)
at XMLHttpRequest.<anonymous> (http://localhost:8000/assets/vendor-ef159bc608efff575c24c5e13c2d1218.js:3:20168)`.
What did I do wrong?
I've solved similar problem recently by downgrading from jQuery 2 to jQuery 1 in bower.json, then deleting jQuery folder in bower_components, then running bower install command.

Categories