Uncaught syntaxerror unexpected token in css

Содержание
  1. Unexpected token > [closed]
  2. 2 Answers 2
  3. Error: Uncaught SyntaxError: Unexpected token I think everything should be good to go, but I don’t understand why the < is somehow throwing this off.. whoops, forgot to show where this is happening! My bad, http://www.marioplanet.com/index.asp Any ideas? Me neither I don’t understand. Maybe you would like to share some code and explain what you are trying to do, etc. Showing the error is one thing but if you want to understand where this error comes from we need to see what is causing it (which undoubtfully is your code). Also tagging your question with the error tag doesn’t bring much valuable information to it. That’s not really a line of code. I mean, you can’t execute it. At least give us enough context to see a full statement. K, my bad, I’ve tried to give it a little more context, and I forgot to give a link, which I originally intended to do.. For me this error was caused by an incorrect file request path and the 404 page being returned was attempting to be parsed, resulting in the error. Hope this help ssomeone 😀 11 Answers 11 This is a browser issue rather than a javascript or JQuery issue; it’s attempting to interpret the angle bracket as an HTML tag. Try doing this when setting up your javascripts: Alternatively, move your javascript to a separate file. Edit: Ahh.. with that link I’ve tracked it down. What I said was the issue wasn’t the issue at all. this is the issue, stripped from the website: ); $('#music_descrip').dialog(< title: '', autoOpen: false, height: 375, width: 500, modal: true, resizable: false, buttons: < 'Without Music': function() < $(this).dialog('close'); $.cookie('autoPlay', 'no', < expires: 365 * 10 >); >, 'With Music': function() < $(this).dialog('close'); $.cookie('autoPlay', 'yes', < expires: 365 * 10 >); > > >); >); My previous suggestion still stands, however: you should enclose intra-tagged scripts in a CDATA block, or move them to a separately linked file. That wasn’t the issue here, but it would have shown the real issue faster. Oh wowwwwwww. Thanks for the spot, but that was pretty lame, anyway, I moved the js to a separate file for cleaner code and maintainability anyway. Thanks! Can you catch such exceptions in jquery? Meaning, if my success method gets this uncaught exceptions, i would like to catch it and show some error message to the user. @noobcode If you don’t structure your markup correctly, the javascript engine is going to fail miserably — or not start at all. How errors in markup are handled are browser specific and I’m not sure any provide a mechanism you can hook to give the user a general purpose «I screwed up with the website you’re trying to view» error message. In addition to this very good answer, I would suggest you to check also if there is a call to an unexistant JS file. I too got this error, when developing a Backbone application using HTML5 push state in conjunction with an .htaccess which redirects any unknown files to index.html. It turns out that when visiting a URL such as /something/5 , my /index.html was effectively being served at /something/index.html (thanks to my .htaccess). This had the effect of breaking all the relative URLs to my JavaScript files (from inside the index.html ), which meant that they should have 404’d on me. However, again due to my htaccess, instead of 404’ing when attempting to retrieve the JS files, they instead returned my index.html. Thus the browser was given an index.html for every JavaScript file it tried to pull in, and when it evaluated the HTML as if it were JavaScript, it returned a JS error due to the leading < (from my tag in index.html). The fix in my case (as I was serving the site from inside a subdirectory) was to add a base tag in my html head. Источник «Uncaught SyntaxError: Unexpected token < " in Bootstrap 2.1.0 bundled with Joomla! 3.0 I’m using Joomla! 3.0, which has Twitter Bootstrap 2.1.0 included. I want to do my own Joomla! template, and I need to use dropdown menus. When I include following CSS/JS: baseurl ?>/templates/template; ?>/css/Site.css" rel="stylesheet" type="text/css"> Uncaught SyntaxError: Unexpected token

    1 Answer 1

    You have syntax error because you tried to include CSS file as it was JavaScript, so change

    
    baseurl ?>/media/jui/css/bootstrap.css" rel="stylesheet" type="text/css" />
    
    
    Also close other link tags properly with /> , not with just >
    
    
    Note you can include jQuery and bootstrap with Joomla through a PHP command just call JHtml::_('bootstrap.framework') (see docs page here for more info docs.joomla.org/Javascript_Frameworks )
    
    
    I ran into this when jumping into node development and not paying close enough attention to external resources. Double check your paths, file extensions, and file contents. Make sure everything JavaScript is .js and everything CSS is .css. Also make sure you're not importing jquery.js as jquery.css. Sounds dumb but it happened to me my first time around so figured it will probably happen to someone else as well.
    
    
    Источник
    jest unexpected token when importing css
    
    
    those isn't in my spec.js but my implementation code, any clue why? I have no problem running my app but jest throw error when I try to run test.
    
    
    Try without extension. eg: import 'react-dates/lib/css/_datepicker. Also please see stackoverflow.com/questions/49263429/… could fix your issue
    
    
    are you using babel-jest ? It looks like babel-jest is missing among your dependencies. That's why jest is not running babel on your ES6+ code before executing tests.
    5 Answers 5
    
    
    The problem is that Jest is hitting these CSS imports and trying to parse them as if they were JavaScript.
    
    
    The "Unexpected token ." message probably comes because the first line of the file it is choking on is a CSS class declaration, i.e. .datepicker: < . >.
    
    
    Anyway, as pointed out in this answer, the way to get around this is to create a file containing a module which exports an empty object. I called mine styleMock.js .
    
    
    Then, you need to create a jest.config.js file in your project root and add:
    module.exports = < moduleNameMapper: < '\.(css|less)$': '/test/jest/__mocks__/styleMock.js', > >;
    
    
    The moduleNameMapper setting tells Jest how to interpret files with different extensions. In this case we simply need to point it at the empty file we just created. Obviously adjust the path to your file accordingly.
    
    
    And note that you can expand the regex above for whichever file endings you need. Mine looks like:
    moduleNameMapper: < '\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/test/jest/__mocks__/fileMock.js', '\.(css|less)$': '/test/jest/__mocks__/styleMock.js', >,
    
    
    where fileMock.js is identical to styleMock.js
    
    
    Alternatively, you could use a module such as jest-transform-stub, which does the same thing for you.
    
    
    Amazing answer! Once I fixed to the file paths to match my project and changed (css|less) to (css|less|scss) , it worked for me. Thanks.
    
    
    I am trying this but i get a configuration error: Could not locate module react-datepicker/dist/react-datepicker.css mapped as: /home/alejo/tecnimaq/tecnilab/frontend/test/jest/__mocks__/styleMock.js. Please check your configuration for these entries: < "moduleNameMapper": < "/\.(css|less)$/": "/home/alejo/tecnimaq/tecnilab/frontend/test/jest/__mocks__/styleMock.js" >, "resolver": undefined >
    
    
    I'm back and appreciating this answer again. For RedwoodJs, I see that this seems to be the point of @redwoodjs\testing\dist\fileMock.js . Unfortunately it omits scss. My fix: const moduleNameMapper = < . config.moduleNameMapper, '\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css|scss|less)$': '@redwoodjs/testing/dist/fileMock.js' >; delete moduleNameMapper['\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css)$']; const configWithEditedModuleNameMapper = < . config, moduleNameMapper: moduleNameMapper >;
    
    
    (That fix needs to go in web\jest.config.js , which then needs to end with module.exports = configWithEditedModuleNameMapper; .)
    
    
    Spun my wheels with this for 20 minutes before I realized that my scripts in package.json pointed to an external jest.config.js ala "test": "jest --config=./jest.config.js --silent", . Moved the moduleNameMapper config to that file and then it worked.
    
    
    For anyone hitting this question in fall 2020 or later, for an error like SyntaxError: Invalid or unexpected token when Jest parses CSS files: True, the error is due to Jest trying to parse the CSS as JavaScript, which wont work. So the updated way to handle this is 3 steps, per the Jest documentation on handling static assets, but you dont need to add an additional package like identity-obj-proxy as @chitra suggested unless you're using CSS Modules. And to contrast @james-hibbard 's suggestions: the fileMock.js now looks slightly different and you don't need to create a jest.config.js .
    
    
    1 in your package.json add this
    < "jest": < "moduleNameMapper": < "\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/__mocks__/fileMock.js", "\.(css|less)$": "/__mocks__/styleMock.js" > > >
    
    
    2 Then create the following two files:
    // __mocks__/styleMock.js module.exports = <>;
    // __mocks__/fileMock.js module.exports = 'test-file-stub';
    
    
    That should fix these specific errors when Jest runs like
    SyntaxError: Invalid or unexpected token > 1 | import '../src/css/console.scss';
    
    
    Источник
  4. 11 Answers 11
  5. «Uncaught SyntaxError: Unexpected token < " in Bootstrap 2.1.0 bundled with Joomla! 3.0
  6. jest unexpected token when importing css
  7. 5 Answers 5

Unexpected token > [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.

I have a script to open a model window.. Chrome gives me «Uncaught SyntaxError: Unexpected token >» on a line that doesn’t even have a closing curly brace. Here is the portion of the script that has the error:

function showm(id1)< window.onscroll=function(); document.getElementById(id1).style.display="block"; document.getElementById(id1).style.top=document.body.scrollTop; > 

I can’t see anything wrong with that (except that you are attempting to assign integers to CSS properties that require lengths). I’m guessing the error is in some surrounding code.

That code you’ve posted does not cause a syntax error. Is that really all of your script? Nothing in that code looks like it has anything to do with opening a window.

it doesnt really open a window, it just makes a div, the modal «window», visible. and no, it isnt all. but the rest of the code isnt where the problem is. and plus, it like 100 lines. would you like me to post that?

2 Answers 2

Try running the entire script through jslint. This may help point you at the cause of the error.

Edit Ok, it’s not quite the syntax of the script that’s the problem. At least not in a way that jslint can detect.

Having played with your live code at http://ft2.hostei.com/ft.v1/, it looks like there are syntax errors in the generated code that your script puts into an onclick attribute in the DOM. Most browsers don’t do a very good job of reporting errors in JavaScript run via such things (what is the file and line number of a piece of script in the onclick attribute of a dynamically inserted element?). This is probably why you get a confusing error message in Chrome. The FireFox error message is different, and also doesn’t have a useful line number, although FireBug does show the code which causes the problem.

This snippet of code is taken from your edit function which is in the inline script block of your HTML:

var sub = document.getElementById('submit'); . sub.setAttribute("onclick", "save(\""+file+"\", document.getElementById('name').value, document.getElementById('text').value"); 

Note that this sets the onclick attribute of an element to invalid JavaScript code:

save("data/wasup.htm", document.getElementById('name').value, document.getElementById('text').value 

Note the missing close paren to finish the call to save .

As an aside, inserting onclick attributes is not a very modern or clean way of adding event handlers in JavaScript. Why are you not using the DOM’s addEventListener to simply hook up a function to the element? If you were using something like jQuery, this would be simpler still.

Источник

Error: Uncaught SyntaxError: Unexpected token

I think everything should be good to go, but I don’t understand why the < is somehow throwing this off.. whoops, forgot to show where this is happening! My bad, http://www.marioplanet.com/index.asp Any ideas?

Me neither I don’t understand. Maybe you would like to share some code and explain what you are trying to do, etc. Showing the error is one thing but if you want to understand where this error comes from we need to see what is causing it (which undoubtfully is your code). Also tagging your question with the error tag doesn’t bring much valuable information to it.

That’s not really a line of code. I mean, you can’t execute it. At least give us enough context to see a full statement.

K, my bad, I’ve tried to give it a little more context, and I forgot to give a link, which I originally intended to do..

For me this error was caused by an incorrect file request path and the 404 page being returned was attempting to be parsed, resulting in the error. Hope this help ssomeone 😀

11 Answers 11

This is a browser issue rather than a javascript or JQuery issue; it’s attempting to interpret the angle bracket as an HTML tag.

Try doing this when setting up your javascripts:

Alternatively, move your javascript to a separate file.

Edit: Ahh.. with that link I’ve tracked it down. What I said was the issue wasn’t the issue at all. this is the issue, stripped from the website:

); $('#music_descrip').dialog(< title: '', autoOpen: false, height: 375, width: 500, modal: true, resizable: false, buttons: < 'Without Music': function() < $(this).dialog('close'); $.cookie('autoPlay', 'no', < expires: 365 * 10 >); >, 'With Music': function() < $(this).dialog('close'); $.cookie('autoPlay', 'yes', < expires: 365 * 10 >); > > >); >); 

My previous suggestion still stands, however: you should enclose intra-tagged scripts in a CDATA block, or move them to a separately linked file.

That wasn’t the issue here, but it would have shown the real issue faster.

Oh wowwwwwww. Thanks for the spot, but that was pretty lame, anyway, I moved the js to a separate file for cleaner code and maintainability anyway. Thanks!

Can you catch such exceptions in jquery? Meaning, if my success method gets this uncaught exceptions, i would like to catch it and show some error message to the user.

@noobcode If you don’t structure your markup correctly, the javascript engine is going to fail miserably — or not start at all. How errors in markup are handled are browser specific and I’m not sure any provide a mechanism you can hook to give the user a general purpose «I screwed up with the website you’re trying to view» error message.

In addition to this very good answer, I would suggest you to check also if there is a call to an unexistant JS file.

I too got this error, when developing a Backbone application using HTML5 push state in conjunction with an .htaccess which redirects any unknown files to index.html.

It turns out that when visiting a URL such as /something/5 , my /index.html was effectively being served at /something/index.html (thanks to my .htaccess). This had the effect of breaking all the relative URLs to my JavaScript files (from inside the index.html ), which meant that they should have 404’d on me.

However, again due to my htaccess, instead of 404’ing when attempting to retrieve the JS files, they instead returned my index.html. Thus the browser was given an index.html for every JavaScript file it tried to pull in, and when it evaluated the HTML as if it were JavaScript, it returned a JS error due to the leading < (from my tag in index.html).

The fix in my case (as I was serving the site from inside a subdirectory) was to add a base tag in my html head.

Источник

«Uncaught SyntaxError: Unexpected token < " in Bootstrap 2.1.0 bundled with Joomla! 3.0

I’m using Joomla! 3.0, which has Twitter Bootstrap 2.1.0 included. I want to do my own Joomla! template, and I need to use dropdown menus. When I include following CSS/JS:

   baseurl ?>/templates/template; ?>/css/Site.css" rel="stylesheet" type="text/css">  
Uncaught SyntaxError: Unexpected token  

1 Answer 1

You have syntax error because you tried to include CSS file as it was JavaScript, so change

 
baseurl ?>/media/jui/css/bootstrap.css" rel="stylesheet" type="text/css" /> 

Also close other link tags properly with/> , not with just >

Note you can include jQuery and bootstrap with Joomla through a PHP command just call JHtml::_('bootstrap.framework') (see docs page here for more info docs.joomla.org/Javascript_Frameworks )

I ran into this when jumping into node development and not paying close enough attention to external resources. Double check your paths, file extensions, and file contents. Make sure everything JavaScript is .js and everything CSS is .css. Also make sure you're not importing jquery.js as jquery.css. Sounds dumb but it happened to me my first time around so figured it will probably happen to someone else as well.

Источник

jest unexpected token when importing css

those isn't in my spec.js but my implementation code, any clue why? I have no problem running my app but jest throw error when I try to run test.

Try without extension. eg: import 'react-dates/lib/css/_datepicker. Also please see stackoverflow.com/questions/49263429/… could fix your issue

are you using babel-jest ? It looks like babel-jest is missing among your dependencies. That's why jest is not running babel on your ES6+ code before executing tests.

5 Answers 5

The problem is that Jest is hitting these CSS imports and trying to parse them as if they were JavaScript.

The "Unexpected token ." message probably comes because the first line of the file it is choking on is a CSS class declaration, i.e. .datepicker: < . >.

Anyway, as pointed out in this answer, the way to get around this is to create a file containing a module which exports an empty object. I called mine styleMock.js .

Then, you need to create a jest.config.js file in your project root and add:

module.exports = < moduleNameMapper: < '\\.(css|less)$': '/test/jest/__mocks__/styleMock.js', > >; 

The moduleNameMapper setting tells Jest how to interpret files with different extensions. In this case we simply need to point it at the empty file we just created. Obviously adjust the path to your file accordingly.

And note that you can expand the regex above for whichever file endings you need. Mine looks like:

moduleNameMapper: < '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/test/jest/__mocks__/fileMock.js', '\\.(css|less)$': '/test/jest/__mocks__/styleMock.js', >, 

where fileMock.js is identical to styleMock.js

Alternatively, you could use a module such as jest-transform-stub, which does the same thing for you.

Amazing answer! Once I fixed to the file paths to match my project and changed (css|less) to (css|less|scss) , it worked for me. Thanks.

I am trying this but i get a configuration error: Could not locate module react-datepicker/dist/react-datepicker.css mapped as: /home/alejo/tecnimaq/tecnilab/frontend/test/jest/__mocks__/styleMock.js. Please check your configuration for these entries: < "moduleNameMapper": < "/\.(css|less)$/": "/home/alejo/tecnimaq/tecnilab/frontend/test/jest/__mocks__/styleMock.js" >, "resolver": undefined >

I'm back and appreciating this answer again. For RedwoodJs, I see that this seems to be the point of @redwoodjs\testing\dist\fileMock.js . Unfortunately it omits scss. My fix: const moduleNameMapper = < . config.moduleNameMapper, '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css|scss|less)$': '@redwoodjs/testing/dist/fileMock.js' >; delete moduleNameMapper['\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css)$']; const configWithEditedModuleNameMapper = < . config, moduleNameMapper: moduleNameMapper >;

(That fix needs to go in web\jest.config.js , which then needs to end with module.exports = configWithEditedModuleNameMapper; .)

Spun my wheels with this for 20 minutes before I realized that my scripts in package.json pointed to an external jest.config.js ala "test": "jest --config=./jest.config.js --silent", . Moved the moduleNameMapper config to that file and then it worked.

For anyone hitting this question in fall 2020 or later, for an error like SyntaxError: Invalid or unexpected token when Jest parses CSS files: True, the error is due to Jest trying to parse the CSS as JavaScript, which wont work. So the updated way to handle this is 3 steps, per the Jest documentation on handling static assets, but you dont need to add an additional package like identity-obj-proxy as @chitra suggested unless you're using CSS Modules. And to contrast @james-hibbard 's suggestions: the fileMock.js now looks slightly different and you don't need to create a jest.config.js .

1 in your package.json add this

< "jest": < "moduleNameMapper": < "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/__mocks__/fileMock.js", "\\.(css|less)$": "/__mocks__/styleMock.js" > > > 

2 Then create the following two files:

// __mocks__/styleMock.js module.exports = <>; 
// __mocks__/fileMock.js module.exports = 'test-file-stub'; 

That should fix these specific errors when Jest runs like

SyntaxError: Invalid or unexpected token > 1 | import '../src/css/console.scss'; 

Источник

Читайте также:  Просто Кексик
Оцените статью