Unexpected token ILLEGAL - brunch generated app.js - node.js

I know this has been asked a million times, but I can't seem to locate the illegal characters in this line:
window.require.register("templates/application", Function('exports, require, module', "module.exports = Ember.TEMPLATES[module.id.replace('templates\\','')] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {\nthis.compilerInfo = [2,'>= 1.0.0-rc.3'];\nhelpers = helpers || Ember.Handlebars.helpers; data = data || {};\n var buffer = '', hashTypes, escapeExpression=this.escapeExpression;\n\n\n hashTypes = {};\n data.buffer.push(escapeExpression(helpers._triageMustache.call(depth0, \"outlet\", {hash:{},contexts:[depth0],types:[\"ID\"],hashTypes:hashTypes,data:data})));\n data.buffer.push(\"\\n\");\n return buffer;\n \n});\n//# sourceURL=templates/application.hbs"));
This line is from the app.js file generated using node/brunch from the simple empty branch of https://github.com/cbosco/ember-brunch.
I get the error:
Uncaught SyntaxError: Unexpected token ILLEGAL
in Chrome when pointing to localhost:3333. Firefox gives the following error:
SyntaxError: unterminated string literal
It looks like it's in the generated "templates" code in app.js. The same problem happens in the cbosco todomvc project.
Steps to recreate:
git clone git://github.com/cbosco/ember-brunch.git ember-skeleton -b empty
brunch new my_app -s ./ember-skeleton
cd my_app
brunch watch -s
point browser to localhost:3333

Related

SyntaxError: Unexpected token =

class Match {
JSDOM = jsdom;
Discord = require("discord.js");
jsdom = require("jsdom");
…
}
This is the code I use, and I get the error:
JSDOM = jsdom();
^
SyntaxError: Unexpected token =
Why? This should work right? This only happens when I try to run the code on repl.it. When I run it on my computer it works fine.
So for anyone wondering, I found the problem. I was importing the project from GitHub, when I made a new REPL and specified node.js as the language, then imported the files, everything worked as expected.

ChartJS Financial candles on NodeJS

I’m trying to make Chartjs-chart-financial in NodeJS. There is no NPM package for this plugin so I have to install it manually.
I do:
Git clone https://github.com/chartjs/chartjs-chart-financial/
cd chartjs-chart-financial
npm install
gulp build
As result I get a file in /dist directory and copy it to my NodeJS project folder.
In my NodeJS app I do:
const Chart = require(‘chart.js’)
const ChartFinancial = require(‘./chartjs-chart-financial.js’)
When I run the app I get:
chartjs-chart-financial.js:227
globalOpts.elements.financial = {
TypeError: Cannot set property ‘financial’ of undefined
I have checked content of Chart.defaults and found that .elements is in ‘global’ so I changed
225 const globalOpts = Chart.defaults.global
316 const globalOpts$1 = Chart.defaults.global
401 const globalOpts$2 = Chart.defaults.global
And eventually Error
Chart.defaults.set(‘ohlc’ ... set is not a function
on line 446
So I changed them to:
446 Chart.defaults.ohlc.datasets.barPercentage = 1.0,
447 Chart.defaults.ohlc.datasets.categoryPercentage = 1.0
Then I got
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
at CandlestickController.draw (C:\inetpub\github\telegram-stream-trades\chartjs-chart-financial.js:213:32)
So I chagned:
213 const rects = me.getMeta();
That handled all the errors. But still no candles drawn.
So probably the way I initially started is incorrect

Babel parser not showing proper filename for sytax error

So I've tried everywhere but can't find any answers to this. I am trying to add some custom functionality to a Gatsby build process that runs on node.js which requires me to get file content and parse into an ast. I am using #babel/parser successfully, however whenever the parser runs into syntax errors it throws an error referencing the file running the parser instead of the file being parsed (i.e. where the syntax error is actually located).
Here is an example from gatsby-node.js where I am trying to run the parsing function:
const contents = fs.readFileSync( file, 'utf-8' );
const ast = parser.parse( contents, {
errorRecovery: true,
plugins: [ 'jsx' ],
sourceFilename: 'SHOWME.js',
sourceType: 'module',
} );
Here is the actual syntax error in the file being parsed named Page.js:
import React from 'react';
import { useGroqQuery } = 'this should break';
And here is the error as displayed in terminal:
"gatsby-node.js" threw an error while running the createPages lifecycle:
Unexpected token (2:24)
119 |
120 | const contents = fs.readFileSync( file, 'utf-8' );
> 121 | const ast = parser.parse( contents, {
| ^
122 | errorRecovery: true,
123 | plugins: [ 'jsx' ],
124 | sourceFilename: 'SHOWME.js',
File: gatsby-node.js:121:20
SyntaxError: Unexpected token (2:24)
- index.js:742 Object._raise
[gatsby-groq]/[#babel]/parser/lib/index.js:742:17
- index.js:735 Object.raiseWithData
[gatsby-groq]/[#babel]/parser/lib/index.js:735:17
- index.js:729 Object.raise
[gatsby-groq]/[#babel]/parser/lib/index.js:729:17
As you can see, it's showing me neither the syntax error itself or the filename, only the line and column numbers. Pretty frustrating to debug. I have tried using the parser's errorRecovery and sourceFilename options but they aren't making a difference here.
Has anyone run into anything similar?

Running my file in node, terminal throwing error syntax error near unexpected token `('

I am attempting to run a file in my node environment on my macbook. I keep getting the following terminal error messages:
/.../filename.js: line 2: syntax error near unexpected token `('
/.../filename.js: line 2: `const fs = require('../build/index.js');'
code:
#!/usr/bin/env node
const fs = require('../build/index.js');
The command I'm giving is:
node index.js
(I know the file names are the same but its calling a different file.)
I can't seem to figure out why it is finding the extra `.
I have tried:
Rewriting the code multiple times.
I started a new file from scratch with the same name (filename.js).
Running the code through jslint
https://www.digitalocean.com/community/questions/syntax-error-near-unexpected-token-in-node-js-for-http
I followed the exact formatting from this article: https://adrianmejia.com/blog/2016/08/12/getting-started-with-node-js-modules-require-exports-imports-npm-and-beyond/
Using double quotes instead of single quotes
Little more background, this is a project I've picked up and this is my first time trying to run it.
EDIT: Code for index.js
'use strict';
var _child_process = require('child_process');
var _logger = require('./logger');
var _logger2 = _interopRequireDefault(_logger);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var l = new _logger2.default();
l.log('Starting backup');
var wd = __dirname.split('/');
var basePath = wd.slice(0, wd.length - 1).join('/');
var execPath = basePath + '/path/filename.js';
var stdout = (0, _child_process.execSync)('. ' + execPath + ' -a ' + basePath + '/something.json -b ' + basePath + '/backups');
l.log(stdout);
The issue is that the index.js calls filename.js through child_process.execSync() method, that's basically "execute this file using shell and give me its output".
Your filename.js has a shebang, and it would do intended (run using node), if not for this tiny dot in execSync() first parameter. It looks like this:
. /some/path/filename.js -a /some/path/something.json -b /some/path/backups
In sh-shells the . is a shorthand for source builtin command, that means "execute this file in shell and return its exit code". Thus, filename.js executes in shell, not in the node.
Just remove this dot (with space after it) and it will work.

Nodejs command line app: unexpected token `else'

I'm trying to create a node command line app.
What I am doing is extracting emails from a document full of information.
But when I have run the command npm link to make the script globally available, I get these errors:
/c/Users/petfle/AppData/Roaming/npm/email-extract: line 11: syntax error near unexpected token `else'
/c/Users/petfle/AppData/Roaming/npm/email-extract: line 11: `else '
My code passed linting, and I can't see any erros. I'm new to node, so it might be something simple, node specific thing that I don't see.
Here is my code:
#!/c/Program\ Files/nodejs/node
var file_stream = require('fs');
var source = process.argv[2];
var output = process.argv[3];
file_stream.readFile(source, 'utf8', function (error, data) {
var list_of_emails = extract_emails(data);
write_to_file(list_of_emails);
});
function extract_emails(data) {
return data.match(/([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/g);
}
function write_to_file(emails) {
file_stream.writeFile(output, emails.join('\n'), 'utf8', function (error) {
console.log('Wrote ' + emails.length + ' lines to ' + output);
});
}
EDIT:
It works if I remove the shebang and run it with node myscript.js file.txt file2.txt. I'm on windows.
EDIT 2:
I'm runing this in the Git Bash. Even on windows it did run a simpler script fine with the shebang.
It works in Linux Mint 15 after removing the shebang line and invoking it through:
$ node code.js emails emailsOut
Also adding the OS-specific line #!/usr/bin/node and chmod +x code.js I can run it through
$ ./code.js emails emailsOut
Windows unfortunately doesn't work with shebang lines as such. A workaround can be found here.

Resources