I am currently trying to get into NodeJS together with the SailsJS framework.
And I want to use coffeescript on the serverside aswell, but after converting all files in config/*.js to config/*.coffee properly with js2coffee, I get the following error when trying to start up the app:
config/400.coffee
SyntaxError: Unexpected token ILLEGAL
pointing to the first character in the file, which is a hashtag for a coffee comment. So it seems the app does not recognize the file as coffeescript, but searching for standard js instead.
I tried installing the package coffee-script and requireing it in
app.js
require('coffee-script');
require('sails').lift(require('optimist').argv);
but it doesn't help.
If I delete 400.coffee, the error appears in the next file 403.coffee etc.
What am I doing wrong? Isn't coffeescript allowed in the config files or am I missing something?
Coffeescript 1.7.0, released Jan 28th, 2014, changed the require('coffee-script') behavior to only load the compiler itself. Now, do load the automatic compiler for .coffee files, you must call require('coffee-script/register') before loading any coffeescript files.
Keep in mind that using this will mean that every .coffee file will be recompiled every time you start node, which could increase startup times. That may or may not be important to you though.
Related
I have a node.js project using webpack that's being deployed to AWS Lambda. However, I also have a single python file in the project that's powering one of the Lambda functions (i ported a legacy python script over to lambda for automation purposes). In my serverless.yml, I've set the appropriate runtimes (node.js/python) for the functions.
My problem is that webpack throws errors about my python file (it's even referencing a python/handler.js file that doesnt exist - the python handler is python/handler.py).
The exact error is:
ERROR in ./python/handler.py 2:0
Module parse failed: Unexpected token (2:0)
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
I just want webpack to bundle the regular .js files, and leave the python file alone. Note that deploying the project without webpack works, and gives me lambda functions powered by javascript and python. Does anyone have any suggestions to my issue?
Simply add **/*.py to your excludeFiles block.
custom:
webpack:
excludeFiles: **/*.py # Provide a glob for files to ignore
You can read more in the documentation
Side note - you may consider trying es-build instead, which is often 10x faster than webpack. You can read more here
I've got the lovely topojson library working for me in a Rails app locally:
https://github.com/topojson/topojson
and it's allowing us to show some nice geoJSON in a google map like so:
I show it with the map.js file exposed, since that seems to be where the trouble is when we deploy to heroku. On heroku the map.js file gives an error on chrome:
maps-....js:27 Uncaught SyntaxError: Unexpected token export
and a similar error (although on a different line) on firefox:
SyntaxError: export declarations may only appear at top level of a module maps-...js:1
I've been in touch with heroku support who suggested locking down our npm version, as it seems like the minified js file is ending up with slightly different content locally than on heroku. I note that I've done everything I can to replicate production mode locally, clobbering and recompiling the static assets etc. and running like so:
RAILS_SERVE_STATIC_FILES=true DEVISE_SECRET_KEY=1234 AIRBRAKE_PROJECT_ID=1234 RAILS_ENV=production bundle exec rails s
but try as I might I cannot replicate the issue on my dev machine.
You can see all the gory details in this PR https://github.com/AgileVentures/LocalSupport/pull/1069 and I was wondering if anyone had any ideas about anything else that could be a difference between my dev machine and heroku that could be leading to the javascript files compiling differently? On heroku we have the following:
export*from"topojson-client";export*from"topojson-server";export*from"topojson-simplify
but there is no mention of the offending export keywords in the static assets compiled locally, but there they are in the files on the heroku server. I've been trying all sort of methods to ensure that I'm deleting cached files and that that the changes I am making are being reflected both locally and on heroku.
I've also been investigating ways to try and handle the export keyword (new in es6) but that seems like an even deeper rabbit hole, i.e. sprockets 4 or webpack or similar.
Anyhow, if anyone has any thoughts on other things that could cause heroku to be operating differently here I'd love to hear them, so I can either lock them down or work out how to replicate the bug locally.
Many thanks in advance
Heroku support are saying that the problem here is using npm with the asset pipeline and the better approach would be to use webpacker
With the aid of node-google module I wrote a simple node module to enable a 'text web search' feature to my web app, presenting results in one of my views.
Since after a quite small number of queries from the same IP Google returns a 503 error, I decide to use the module on the client, so the limit is per client, not per server.
I did use browserify to convert the node module to a script to be sourced in a client page.
The script just requires 'google.js', and it's just 20 lines of javascript long:
'use strict';
var google = require('google');
var Google = Object.create({});
var Google.search = function(text, callback) {
...
});
// end of the script
The command I use is simply:
$ browserify google-search-module.js -o app/scripts/google-search.js
The problem is that the output browserify produces is far bigger than I did expect: a 1.2 kB module becomes a 2.4 MB script! Probably it's including all 'google' dependencies, too, but..,
The question is: is this normal? Is my search page expected to load a 2.4 MB file just to search some text on Google?
I'm quite sure I'm missing something, but can't understand what... :-(
That is expected behaviour. Browserify loads all modules imported with require() recursively, and outputs a single file. There are ways around this, but they are unlikely to work in your paticular case.
Normally, with Browserify, you might work with one huge bundle in development, but then build a much smaller production version. If you were using jQuery, for example, you could install the package locally into your node_modules folder. Then, for production, you could set the --exclude flag to have Browserify ignore anything in your node_modules folder, instead relying on a CDN to deliver jQuery to the client.
I say this is unlikely to work in your case because node-google really is a Node module. There is no guarantee that it will work in the browser (it may or may not). You really should determine if it is working before you start planning your next line of attack.
If it is working, you have two possible remedies:
Minify your bundle and make sure it is served gzipped. The resulting file size will likely be fewer than 100kB, if you can live with that.
Find some other module for doing a Google search, or implement one of your own. This is probably the best solution unless you must use node-google for some reason.
Of course, if it isn't working in the browser anyway, only the second solution is available.
I use Visual Studio 2013 and .NET 4.5 for an MVC project.
I've learning to use AngularJS via several videos on Pluralsight and one of them walks through the process of using Grunt to clean the output directory, then use ngmin to min-safe the Javascript files.
My process is using a gruntfile.js to clean and run ngmin against the javascript files in my solution, then put them in a directory called app_built. This is executed via a batch file in the pre-build for the project and then I include it via a ScriptBundle with IncludeDirectory pointing to the app_built directory. My intent is to use the Bundling features of .NET 4.5 to do the rest of the minification and concatenation of the Javascript after all the files have been min-safed via Grunt.
I specify the path to the min-safed files with the following:
bundles.Add(new ScriptBundle("~/bundles/minSafed")
.IncludeDirectory("~/app_built/", "*.js", true));
If I run this on my local machine, it runs fine without a hitch. The Javascript is minified and bundled as I'd expect and the resulting web application runs fine as well.
If I publish the website to a remote server, I get a server error that the "Directory does not exist. Parameter name: directoryVirtualPath". I assume this error is saying that it's unable to find the directory populated with my many *.js files. I also assume this is because they weren't published since they aren't part of the solution, even though the folder they reside in is a part of the solution (it's just empty within the solution explorer in Visual Studio).
If my assumption is correct, what can I do to add these files to my solution so they'll be published with the rest of my web application with minimal effort on my end each time?
And if I'm incorrect in the assumption, what I can I do to resolve this otherwise?
Thanks!
I never did find a great way of going about this. I found information at http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx that seems related, but I was unable to make it work.
Rather, since I knew the name of the outputted file, I simply created such an empty file in my project and referenced that where I needed to. I then had the pre-build task replace the contents of that file with the externally minified version and it would be packaged with the project as necessary, so it works well enough.
Am using jit tree in my rails 4 application.
http://philogb.github.io/jit/.
While using it in local I am not getting any error. But When I deploy my app into heroku I get the following error on assets precompilation.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
SyntaxError: Invalid regular expression: /(C-1))}z.computePositionStep(A,y);if(C&&x>=C) {B.onComplete();return}}B.onStep(Math.round(x/: Unmatched ')'
(in /tmp/build_tposeydajlt8/app/assets/javascripts/application.js)
Try formatting that particular line in your code. Normally, it throws this error when you have a post/pre-increment before dividing. For example, if you have,
i++/(C-1)
make it
(i++)/(C-1)
This may help, it may not: I was also getting asset pre-compilation errors compiling Jit, so I updated the uglifier gem with bundle update uglifier, and it started working. However, the uglification itself has also been causing problems, so I might just not uglify it since the JS will normally be downloaded compressed and that should provide sufficient file size reduction.
If that doesn't work, another thing you could do is, instead of downloading the full Jit package, just download the bits of Jit you need by using the Custom build option found here: http://philogb.github.io/jit/builder.html ; perhaps the error is caused by a file you don't need.
Thanks