I would like you to help me repair an error that I have, is that every time I create a new project in react with the command npx create-react-app app-name and followed by a cd to the directory and an npm start, I says everything is correct:
Compiled successfully!
You can now view cacas in the browser.
Local: http://localhost:3000
On Your Network: http://172.27.248.214:3000
Note that the development build is not optimized.
To create a production build, use yarn build.
enter image description here
Followed by this I go to the browser, and I give f12 to start the inspector, and I run into the following errors:
First error
Error handling response: SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at chrome-extension://bmjmipppabdlpjccanalncobmbacckjn/js/content/content.js:60:21
According to the error is in this line
data = JSON.parse(data.cs_template);
Full code shown
document.addEventListener('DOMContentLoaded', function () {
for (var i = 0; i < blacklist.length; i++) {
if (location.href.search(blacklist[i]) > 0)
return;
}
cStyle = document.createElement('style');
cStyle.id = 'cs_cursor_css_no_hd';
document.head.appendChild(cStyle);
if (!document.getElementById('elem_ext')) {
elem_ext = document.createElement('div');
elem_ext.id = 'elem_ext';
elem_ext.style.display = 'none';
document.documentElement.appendChild(elem_ext);
}
chrome.storage.local.get('storage_data', function (data) {
if (localStorage.hasOwnProperty('storage_data'))
localStorage.removeItem('storage_data');
localStorage.setItem('storage_data', data.storage_data);
document.documentElement.dataset.csCursorMode = hd_mode;
insert_cs_script();
})
chrome.storage.local.get('cs_template', function (data) {
data = JSON.parse(data.cs_template);
js = document.createElement('script');
js.id = 'cs_cursor_template';
js.innerHTML = data.template;
document.head.appendChild(js);
});
})
Image showing what I already wrote above
enter image description here
Second error
Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at main.js:97
The error sends me to this part of code
var storage_data = (localStorage.hasOwnProperty('storage_data')) ? JSON.parse(localStorage.getItem('storage_data')) : {};
enter image description here
Third error
Uncaught ReferenceError: showCsCursorNonHD is not defined
at <anonymous>:1:35
The third error shows me this
cs_hd_mode = false; showCsCursorNonHD(); hideCsCursor();
enter image description here
It is a new project, without any change
enter image description here
Directories
enter image description here
enter image description here
I have been using WSL2 for more than a year and about a month ago these errors began to appear when creating a new project in react
I believe the issue is that you are trying to call JSON.parse(...) on something that is already a JS object. your data in the callback to chrome.storage.local.get('cs_template',...) is already a JS object. I am not sure what the structure of your data is, but data should be the actual cs_template object that can be accessed like data.cs_template in the callback function.
Related
I'm trying to embed Pdf tron to my React application. I'm receiving this error when I'm clicking on the tab I want to filter to find the relative pdf file.
const handleFilteredDocs = (id)=>{
const filteredDoc = props.location.documents && props.location.documents.filter(doc=>{
return doc.controlId === id
})
setFileteredDoc(filteredDoc)
setPdfPath(filteredDoc[0].filePath)
WebViewer(
{
path: 'lib',
initialDoc: `lib/pdf/${pdfPath}`,
extension: "pdf"
},
viewer.current,
).then((instance) => {
const { docViewer, Annotations } = instance;
const annotManager = docViewer.getAnnotationManager();
docViewer.on('documentLoaded', () => {
const rectangleAnnot = new Annotations.RectangleAnnotation();
rectangleAnnot.PageNumber = 1;
// values are in page coordinates with (0, 0) in the top left
rectangleAnnot.X = 100;
rectangleAnnot.Y = 150;
rectangleAnnot.Width = 200;
rectangleAnnot.Height = 50;
rectangleAnnot.Author = annotManager.getCurrentUser();
annotManager.addAnnotation(rectangleAnnot);
// need to draw the annotation otherwise it won't show up until the page is refreshed
annotManager.redrawAnnotation(rectangleAnnot);
});
});
}
I'm thinking is because the ref component didn't receive in time the pdfPath state and then throw the error. I've tried to place a separate button to load the pdf with the pdfPath correctly updated and in that case worked. What can i do make it render correctly there?
this is the error I get from the console:
(index)
Value
UI version "7.3.0"
Core version "7.3.0"
Build "Mi8yMi8yMDIxfDZmZmNhOTdmMQ=="
WebViewer Server false
Full API false
Object
CoreControls.js:189 Could not use incremental download for url /lib/pdf/. Reason: The file is not linearized.
CoreControls.js:189
{message: "The file is not linearized."}
CoreControls.js:189 There may be some degradation of performance. Your server has not been configured to serve .gz. and .br. files with the expected Content-Encoding. See http://www.pdftron.com/kb_content_encoding for instructions on how to resolve this.
CoreControls.js:189 There may be some degradation of performance. Your server has not been configured to serve .gz. and .br. files with the expected Content-Encoding. See http://www.pdftron.com/kb_content_encoding for instructions on how to resolve this.
CoreControls.js:189 There may be some degradation of performance. Your server has not been configured to serve .gz. and .br. files with the expected Content-Encoding. See http://www.pdftron.com/kb_content_encoding for instructions on how to resolve this.
81150ece-4c18-41b0-b551-b92f332bd17f:1
81150ece-4c18-41b0-b551-b92f332bd17f:1 PDFNet is running in demo mode.
81150ece-4c18-41b0-b551-b92f332bd17f:1 Permission: read
CoreControls.js:922 Uncaught (in promise)
{message: "Exception: ↵ Message: PDF header not found. The f… Function : SkipHeader↵ Linenumber : 1139↵", type: "InvalidPDF"}
Thank you guys for any help I will get on this!
The value of "pdfPath" isn't set to "filteredDoc[0].filePath" yet after you call "setPdfPath" (it'll still be the initial state till the next render). One thing you can do is pass a callback function when using "setState" to call "WebViewer()" after "pdfPath" has been updated
https://reactjs.org/docs/react-component.html#setstate
Also there is a guide on how to add PDFtron to a React project in the following link
https://www.pdftron.com/documentation/web/get-started/react/
One thing to note, is it's does the following
useEffect(() => {
// will only run once
WebViewer()
}, [])
By doing the above, "WebViewer" is only initialized once. It might be a good idea to do something similar and use "loadDocument" (https://www.pdftron.com/documentation/web/guides/best-practices/#loading-documents-with-loaddocument) when switching between documents instead of reinitializing WebViewer each time the state changes
I'm facing with a mysterious error. When I'm trying to send one specific query to the server, I'm receiving the following error
DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
at dispatchXhrRequest (http://localhost:6789/static/js/20.chunk.js:180790:13)
at new Promise (<anonymous>)
at xhrAdapter (http://localhost:6789/static/js/20.chunk.js:180773:10)
at dispatchRequest (http://localhost:6789/static/js/20.chunk.js:181396:10)
And here I logged the actual url string
http://localhost:3000/users/5/payments/disconnect
If I send the same query but from my hosting to dev server, I see error 404 and url like this
https://example.com/users%E2%80%8B/5%E2%80%8B/payments%E2%80%8B/disconnect
This is my function which sends the query
const query = `${url}/users/${userId}/payments/disconnect`;
console.debug('Url', query);
try {
const { status } = await axios.delete(query);
return status;
} catch (e) {
console.debug(e);
return 500;
}
}
Interesting thing, all other endpoints work fine. The same behavior on chrome and firefox.
What can cause problems like this?
%E2%80%8B is a U+200B : ZERO WIDTH SPACE which you've somehow managed to pollute your string with.
You can see them in your source code if you copy/paste the const query = `${url}/users/${userId}/payments/disconnect`; line into this app.
It is probably most easily removed by editing that line like this:
Position the cursor after the character after the /
Press Backspace until the character before the / is deleted
Retype the three characters you desire
I just built an angularjs app using geofire for location. It works perfectly in production but has issues when i deploy it to firebase. I believe the error should be from here
getLocations(radius: number, coords: Array<number>) {
console.log(radius, coords)
this.geoFire.query({
center: coords,
radius: radius
})
.on('key_entered', (userKey, location, distance) => {
//we need to check this because this.hits the behavioursubject already cached previous result and geofire fetches again each time we go back to homepage
const existAlready = this.hits.value.filter(h=>h.userKey === userKey)
if(existAlready.length > 0){
return
}
console.log(userKey)
const u = this.userList.query.ref
.child(`/${userKey}`)
.on('value',s=>{
const {name, address} = s.val()
console.log(s.val())
let hit = {
location,
distance,
name,
address,
userKey
}
let currentHits = this.hits.value
currentHits.push(hit)
this.hits.next(currentHits)
this.eventService.sendMessage(Constants.EVENT_MESSAGES.LOADING, true)
})
})
}
The above code is meant to fetch the locations around me as soon as the app loads. But instead i get this error
#firebase/database: FIREBASE WARNING: Exception was thrown by user
callback. TypeError: Cannot read property 'myID' of undefined
The error only comes in production
I have corrected the error with the following versions of libraries
npm uninstall firebase
npm uninstall angularfire2
npm install firebase#^4.11.0
npm install angularfire2#^5.0.0-rc.6
I am getting this same error in production in my application as well. The only thing that seems to fix it is clearing my google cache, history, and cookies. It isn't a permanent fix in the slightest, but try and see if it helps.
Not sure if that's the solution but that worked for me. I think the real problem happens once you deploy a new build and not clear the cache.
So for me, eveytime i deploy, i have to clear the cache again.
interesting enough, this just happens in chrome. I tested it in Edge and i don't have to go through that.
I've successfully instantiated a simple AudioWorklet in React and wish to start a simple oscillator like in Google's example. In order to test run it, I am rendering a button whose onClick event calls the following:
src/App.jsx:
userGesture(){
//create a new AudioContext
this.context = new AudioContext();
//Add our Processor module to the AudioWorklet
this.context.audioWorklet.addModule('worklet/processor.js').then(() => {
//Create an oscillator and run it through the processor
let oscillator = new OscillatorNode(this.context);
let bypasser = new MyWorkletNode(this.context, 'my-worklet-processor');
//Connect to the context's destination and start
oscillator.connect(bypasser).connect(this.context.destination);
oscillator.start();
})
.catch((e => console.log(e)))
}
The problem is, on every click, addModule method is returning the following error:
DOMException: The user aborted a request.
I am running Chrome v66 on Ubuntu v16.0.4.
src/worklet/worklet-node.js:
export default class MyWorkletNode extends window.AudioWorkletNode {
constructor(context) {
super(context, 'my-worklet-processor');
}
}
src/worklet/processor.js
class MyWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process(inputs, outputs) {
let input = inputs[0];
let output = outputs[0];
for (let channel = 0; channel < output.length; ++channel) {
output[channel].set(input[channel]);
}
return true;
}
}
registerProcessor('my-worklet-processor', MyWorkletProcessor);
My code is straight JavaScript, not React, but I got the same error because the path provided to addModule was incorrect. In my case, both the script that calls addModule and the script provided as the argument to addModule reside in the same directory ("js"). In spite of that, I still had to include this directory in the path to eliminate the error:
...addModule('js/StreamTransmitter.js')...
I hope this helps. Good luck!
For anyone else getting this mysterious error, swallow your pride and check the following:
The processor doesn't have any errors.
The processor is calling external modules with proper path to the external file(s).
The external modules don't have any errors.
The promise will abort when external modules that are loaded via "import" have errors, or the paths to the modules can't be resolved (e.g. the path's to the modules are wrong and don't point to existing files).
This worked for me: serve your worklet files from public folder instead of src. The addModule(url) function points there by default, so addModule('worklets/foo.js') references file public\worklets\foo.js
Source: https://hackernoon.com/implementing-audioworklets-with-react-8a80a470474
This seems to be a bug in the Chromium module loader, it parses the worklet/processor.js file by removing whitespace, which in turn causes it to have JavaScript syntax errors everywhere, which then finally causes this generic non-explanatory error message to show up.
The solution is to serve your worklet-processors (e.g. worklet/processor.js in your case) with:
Content-Type: application/javascript
or
Content-Type: text/javascript
I also experienced this error but due to a Webpack issue.
Turns out webpack doesn't support worklets like it supports web workers (see this issue).
I would recommend using worker-url with webpack.
Install worker-url
npm i --save-dev worker-url
Update your webpack config to include the WorkerUrl plugin.
const WorkerUrlPlugin = require('worker-url/plugin');
module.exports = {
// ...
plugins: [new WorkerUrlPlugin()],
// ...
};
Use WorkerUrl like so:
import { WorkerUrl } from 'worker-url';
const workletUrl = new WorkerUrl(
new URL('./random-noise-processor', import.meta.url),
{ name: 'worklet' },
);
await context.audioWorklet.addModule(workletUrl);
The Error "DOMException: The user aborted a request." happens when the AudioWorklet.addModule() function cannot load the file from the path or URL you provided. Refer to this MDN page
The api AudioWorklet.addModule() expects a String containing the URL of a JavaScript file with the module to add.
It can be an internal URL that points to your public folder where the browser loads your static files in this case -> 'worklet/processor.js if the worklet folder is inside the public directory of your React app.
You can modify your code as below.
this.context.audioWorklet.addModule('worklet/processor.js')
In this case the audioWorklet.addModule() method expects the path to point to your public folder. It can also be an external URL for example a link to Github repository that loads the JS file.
Changing:
this.context.audioWorklet.addModule('worklet/processor.js')
with
this.context.audioWorklet.addModule('../worklet/processor.js')
worked for me.
I am getting this parsing error whenever I try to gulp serve.
This is the code for which gulp is giving error. I have written a function which takes up a object of FormData type and checks for any of its value to be undefined and if it is then set it to blank string.
function setUndefinedFields(data) {
for (var pair of data.entries()) {
if (pair[1] === 'undefined') {
data.set(pair[0], '');
}
}
return data;
}
But when I perform gulp serve it gives parsing error: unexpected identifier in terminal and in browser console it shows this error
Although if I comment the function perform gulp serve and uncomment the function, then the code works fine.
Edit :
This function is called after appending form data values
var data = new FormData();
data.append('jobTitle', vacancy.jobTitle);
data.append('compulsoryReqs', vacancy.compulsoryReqs);
data.append('preferredReqs', vacancy.preferredReqs);
data.append('company', vacancy.company);
data = setUndefinedFields(data);
Now if any of the field value is undefined the function will replace the value with ''.