Failed to Compile: Parsing error unexpected token. The error is on line 20
I am new to React I was following a Brad Traversy tutorial and cant seem to debug this code error. I included the full code below.
./src/Components/AddProject.js
Line 20: Parsing error: Unexpected token
18 | e.preventDefault();
19 | }
> 20 | if(this.refs.title.value === ''){
| ^
21 | alert('Title is required');
22 | } else {
23 | this.setState({newProject:{
You cannot attach flying code in an ES6 JavaScript Class.
It actually doesn't mean anything.
A ES6 Javascript Class will only accept constructor, fields and methods.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
Are you sure that the code below the line of the syntax error shouldn't be wrapped into a method or into render() ?
Related
I want to use mssql in a vue-electron project.
I installed mssql with npm.
When i want to run the app, i get the following error:
ERROR Failed to compile with 2 errors
error in ./node_modules/mssql/lib/tedious/connection-pool.js
Module parse failed: Unexpected token (39:63)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| cfg.options.database = cfg.options.database || this.config.database
| cfg.options.port = cfg.options.port || this.config.port
> cfg.options.connectTimeout = cfg.options.connectTimeout ?? this.config.connectionTimeout ?? this.config.timeout ?? 15000
| cfg.options.requestTimeout = cfg.options.requestTimeout ?? this.config.requestTimeout ?? this.config.timeout ?? 15000
| cfg.options.tdsVersion = cfg.options.tdsVersion || '7_4'
# ./node_modules/mssql/lib/tedious/index.js 4:23-51
# ./node_modules/mssql/index.js
# ./src/modules/db.js
# ./src/background.js
# multi ./src/background.js
error in ./node_modules/mssql/lib/tedious/request.js
Module parse failed: Unexpected token (446:15)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const req = new tds.Request(command, err => {
| // tedious v15 has started using AggregateErrors to wrap multiple errors into single error objects
> (err?.errors ? err.errors : [err]).forEach((e, i, { length }) => {
| // to make sure we handle no-sql errors as well
| if (e && (!errors.length || (errors.length && errors.length >= length && e.message !== errors[errors.length - length + i].message))) {
# ./node_modules/mssql/lib/tedious/index.js 6:16-36
# ./node_modules/mssql/index.js
# ./src/modules/db.js
# ./src/background.js
# multi ./src/background.js
Can someone please help me?
enter image description here
./src/componentes/Navbar.jsx 159:17
Module parse failed: Unexpected token (159:17)
You may need an appropriate loader to handle this file type.
| columnNumber: 21
| }
}, currentUser?.username), currentUser ? /#PURE/React.createElement("span", {
| onClick: logout,
| __self: _this,
The following error is coming in build time:
src/views/contact-page/contact.page.tsx
Line 25:29: Parsing error: Missing semicolon.
23 | const [test, setTest] = useState<string | null>(null);
24 | setTest("test");
> 25 | const test2: string = test!;
| ^
26 |
Please explain why I could not use not-null assertion operator?
I don't believe this is valid JS (Or typescript) syntax.
const test2: string = test!;
The documentation for TS doesn't list this anywhere as a valid check for null - you can do something like this with objects but I don't believe you can do this for a variable like this.
let s = e!.name; // Assert that e is non-null and access name
Even if that did work, your variable would just be undefined instead of null in the case that test was null.
I am trying to write code for a small utility class that detects change in orientation. Unfortunately, the only way I found to access these fields window.orientation and window.screen.orientation
I can see that window.orientation is deprecated. The alternative I found is the experimental detection api that is not supported on Safari. And so I decided to stick to the deprecated apis for now till I find something better.
Now the other challenge I am facing is whilst mocking access to these readonly field
I am facing a similar problem when trying same approach with window.orientation.
Essentially properties we are trying to alter are readonly properties.
What is the correct approach in this situation?
Note the deprecation warning for window.orientation that I see is present in lib.dom.d.ts
You can use Object.defineProperty() to do this.
E.g.
index.ts:
export function main() {
const orientation = window.screen.orientation;
return orientation.type;
}
index.test.ts:
import { main } from './';
describe('63570675', () => {
it('should pass', () => {
Object.defineProperty(window.screen, 'orientation', {
value: { type: 'landscape-primary' },
});
const actual = main();
expect(actual).toEqual('landscape-primary');
});
});
unit test result with coverage report:
PASS src/stackoverflow/63570675/index.test.ts
63570675
✓ should pass (5ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
index.ts | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.292s, estimated 14s
source code: https://github.com/mrdulin/jest-codelab/tree/master/src/stackoverflow/63570675
Getting an error on this
<body onload="setupZoom();" style={{background:url("/img/bg.jpg") repeat-x #fff}}>
Babel is complaining either about regular expressions when I take the double quotes out, or an unexpected token ,.
{ SyntaxError: /Users/robert/multiDomainCMS/views/winwinhost.com/index.jsx: Unexpected token, expected "," (49:72)
47 | <title>Unlimited Windows Web Hosting, Unlimited Reseller Hosting, Web hosting & Domain Names</title>
48 | </head>
> 49 | <body onload="setupZoom();" style={{background:url("/img/bg.jpg") repeat-x #fff}}>
| ^
50 |
51 | <div class="d_container">
52 | <div class="d_header">
at Object.raise (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:3831:17)
at Object.unexpected (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:5143:16)
at Object.expect (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:5135:28)
at Object.parseObj (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:6600:14)
at Object.parseExprAtom (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:6229:21)
at Object.parseExprAtom (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:3552:20)
at Object.parseExprSubscripts (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:5862:23)
at Object.parseMaybeUnary (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:5842:21)
at Object.parseExprOps (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:5729:23)
at Object.parseMaybeConditional (/Users/robert/multiDomainCMS/node_modules/#babel/parser/lib/index.js:5702:23)
pos: 3141,
loc: Position { line: 49, column: 72 },
code: 'BABEL_PARSE_ERROR' }
I would really appreciate some help, because I have no clue:
What am I doing wrong?
You forgot to add single quotes to the background value <body onload="setupZoom();" style={{background: 'url("/img/bg.jpg") repeat-x #fff'}}>