I am new to Jade and I am having some problems with the Scripts.
In some of them, I get Unexpected Token errors... this is one example:
script
$(document).ready({
$('#answer').keyup(function(e) {
$('#preview').html($('#answer').val());
});
});
This should work fine in common HTML, but with Jade it says:
Uncaught SyntaxError: Unexpected token (
Do I have to use any special syntax with Jade?
Thanks.
In jade, script should be followed by .(dot)
like => script. (or) script(type="text/javascript").
Related
Has anyone experience the following JavaScript syntax error inside a JavaScript file for a cookie alert and have a solution to it? I am getting the error code below.
SyntaxError: Unexpected token ':' at https://*******.com/assets/web/assets/cookies-alert-plugin/cookies-alert-script.js:16:447 at new Promise (<anonymous>) at b (https://*******.com/assets/web/assets/cookies-alert-plugin/cookies-alert-script.js:16:167) at https://***********.com/assets/web/assets/cookies-alert-plugin/cookies-alert-script.js:17:142
I am getting an error that says SyntaxError: Unexpected token a in JSON at position 0
and I cannot find any information on what "a" means. I know that the JSON is not undefined.
Can anyone help me understand what is causing this error?
Here is the code block that is causing the error:
let db_creds = await getDBCredentials();
console.log(db_creds)
const pool = new Pool(JSON.parse(db_creds['SecretString']));
console.log(pool)
Unexpected Token < in JSON at Position 0. From time to time when working with JSON data, you might stumble into errors regarding JSON formatting. For instance, if you try to parse a malformed JSON with the JSON. ... json() method on the fetch object, it can result in a JavaScript exception being thrown.
What Is JSON and How to Handle an “Unexpected Token” Error
Well for me it was because the port was already in use and it must be sending HTML, you can try killing the port by running the below command in cmd(admin mode)
taskkill /F /IM node.exe
I'm trying to use libarchive.js to decompress a zip file that protected by a password.
import {Archive} from 'libarchive.js/main.js';
Archive.init({
workerUrl: 'libarchive.js/dist/worker-bundle.js'
});
document.getElementById('file').addEventListener('change', async (e) => {
const file = e.currentTarget.files[0];
const archive = await Archive.open(file);
let obj = await archive.extractFiles();
console.log(obj);
});
When I run this code, the console shows below output.
I have tried many workerUrl like below. But the result is same.
workerUrl: 'libarchive.js/dist/worker-bundle.js'
workerUrl: '/libarchive.js/dist/worker-bundle.js'
workerUrl: '../libarchive.js/dist/worker-bundle.js'
workerUrl: '../../libarchive.js/dist/worker-bundle.js'
workerUrl: '/node_modules/libarchive.js/dist/worker-bundle.js'
workerUrl: '../node_modules/libarchive.js/dist/worker-bundle.js'
workerUrl: '../../node_modules/libarchive.js/dist/worker-bundle.js'
What is the problem?
Thanks.
Whenever you see this:
▶ Uncaught SyntaxError: Unexpected token '<' some-file.js:1
It's usually because the request to load some-file.js returned an HTML page displaying a 404 error, but it's being interpreted as JavaScript and crashing on the very first character, which in the source of an HTML page is usually <.
To solve your problem, you can try the following URL from this answer:
/lib/worker-bundle.js
Or you can try to view worker-bundle.js directly in a browser. Either you will locate the correct URL, or you will learn that your server is simply not serving that file at all.
I used this code.
Archive.init({
workerUrl: '/libarchive.js/dist/worker-bundle.js',
});
And I put libarchive.js in /public folder of my Vue project.
It worked.
I have a JavaScript application which is running in Node.js environment and communicates to its clients ( also in JavaScript ) using a ZeroMQ. The messages come on the server in JSON format.
The application code throws it out
Node.js SyntaxError: Unexpected token in JSON at position 0
when it is parsed using JSON.parse(). I'm unable to figure out the issue. I've verified the JSON using http://jsonlint.com
Any help with JSON.parse() is welcome.
Edited:01/10/17, 15:33
Here are the client and server JavaScript code files. You'll need to create the .js files, can't post such a big code.
The JSON data file is also provided.
You'll need to launch the server.js and client.js and then the server console will print out the exception for unrecognized character.
https://www.4shared.com/folder/6VFJqrgU/javascript.html
Stackoverflow imposes link posting restrictions so had to post one link with all the files.
Just for info, I'm a C++ programmer, so don't bother about the code formatting or style of programming. I had to do it for a project need.
Edit 02/10/17, 11:50: Well it turns out that it is the JSON.parse() method which is unable to parse the json. But, I added a .trim() call to the args[1].toString() and the error has moved downstream. Unexpected token o in JSON at position 10. I don't understand what is wrong!!
Edit 04/10/17: Here is the minimal code.
var fs = require('fs');
try
{
var event = fs.readFileSync('demoReport.json', 'utf8');
console.log(event);
var eventObj = JSON.parse(event);
var reportName = event["ReportName"];
var reportData = event["ReportData"];
console.log(reportData);
}
catch(error)
{
console.log("JSON parsing failed: " + error);
}
This is the json:
{"EventName":"ReportGenEvent","TemplateFileNameLocation":"File location","ReportFormat":".pdf","ReportName":"TestReport","ReportLocation":"report location","Locale":"French","ReportData":{"dateTime":"2017-09-29T00:05:22.824Z","streamName":"","measurementTime":"2017-04-01T01:13:25.000Z","durationSeconds":0.0,"outOfBand":false,"notFinal":false,"newMeasurement":false,"savedFileName":"","measurementType":"Unknown","analysisElapsedSeconds":1.3462,"analysisElapsedCPUSecs":0.0624004,"geometryID":"GEOM","geometryDescription":"","measurementUUID":"6060c80f-007c-4992-88f8-55e2200d99b7","backgroundUUID":"","measurementWorkflowID":"Measurement","instrumentProperties":{"classCode":8,"description":"","manufacturer":"","model":"","properties":"locationName=Home latitude=25 longitude=20 elevation=30","serialNumber":"product/1","versionInformation":"=V1.0"}}}
Thanks.
I have a Gruntfile, which setups a Connect Server, and I'm trying to add mod_rewrite module (https://www.npmjs.com/package/connect-modrewrite) to add some rules.
Basically, What I need to do, is to add a rewrite for all '^/invite/(.*)$ to the root of my site.
For that I have this config in my Gruntfile.js:
...
middleware: function (connect) {
var middlewares = [];
middlewares.push(modRewrite(['^/invite/(.*)$ / [L]']));
middlewares.push(connect.static(appConfig.app))
return middlewares;
}
...
The route seems to work, since if I check on the inspector, the html of the root page is there.
However, I get this message:
(index):1 Uncaught SyntaxError: Unexpected token <
What is wrong?
EDIT
Errors: