webpack silently continues despite typescript errors - coffeescript

I'm playing around with typescript in an existing coffeescript project that uses gulp and webpack.
I noticed when there's a syntax error in the coffeescript, it will fail the gulp task and not continue with the following steps, which is the desired behavior. With the typescript loader I'm using (ts-loader), I can see error messages in the terminal, but the webpack task succeeds from gulp's perspective and continues on. I imagine this is a difference in how the coffeescript loader and the typescript loader handle errors.
For example, I can add the following typescript file:
function greet(name: string) {
return 'Hello '+name;
}
export = greet;
{
and see the error in the build:
ERROR in ./bin/arranged/webkit/hcube/dummy.ts
(8,1): error TS1005: '}' expected.
but it still continues with the rest of the build like webpack didn't return any errors.
I realize that unlike coffeescript, typescript has a lot of inter-file dependencies, which makes the ts-loader much more complex, but I feel like it should still be failing at some point. Running the typescript compiler on the command line returns the expected exit code when there are syntax errors, so I feel like the problem lies in the loader itself.
In the after-compile plugin of ts-loader should it be reporting errors to webpack differently to propogate up? Right now it looks like it just attaches the errors to webpack in the after-compile plugin and webpack just keeps on trucking (see https://github.com/TypeStrong/ts-loader/blob/master/index.ts#L398). Should the loader be raising an error in this plugin if errors are encountered? Or calling the callback differently? Or should this be handled in some other part of the loader? Again, this particular example is a syntax error, so I imagine it would be caught/raised before after-compile is executed.

Related

A constructor from a node module I'm importing works when using Create React App, but errors in ParcelJS. What is going on?

I'm converting a project that was built using Create React App to use ParcelJS as a bundler instead. Strangely, a dependency that I imported during development (#twilio/voice-sdk) works fine in the CRA version of the application, but I get the following error when I try to invoke the constructor in the Parcel version:
TypeError: (this._options.AudioHelper || audiohelper_1.default) is not a constructor
The package is identical between both (#v2.1.1, the latest). I'm importing using ESM syntax, so:
import { Device } from '#twilio/voice-sdk'
I trying using CommonJS syntax (require) and it still didn't work. I've dug into the compiled code, and that seems to be the issue. I imagine there are a lot of differences, but one that I've noticed is here:
On the left is the code compiled by Create React App, which does seem to be exporting something more substantial than on the left - is the export just an empty object? If so, it's no wonder I'm getting a constructor error.
Unfortunately, no amount of googling and SO sleuthing has clarified what I could do to make ParcelJS transpile this dependency properly, if that's the issue. I've tried to make the babel config for ParcelJS match CRA more closely by adding the following to a babel.config.json
{
"plugins": [
"#babel/plugin-transform-modules-commonjs"
]
}
But no luck. Any ideas from where to go from here, or is it time to switch to Webpack?
It looks like Twilio package has a problem when using Parcel 2: https://github.com/twilio/twilio-voice.js/issues/101

Migrating to Dart 2 I get a "check imports error" that means that some templates have not been generated

I'm trying to migrate to Dart 2, I have a lot of packages and up to now I could do my job with not so much problems.
Now I'm getting a strange error bot with DDC and dart2js:
[SEVERE] build_web_compilers|entrypoint on web/main.dart (cached):
Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).
Please check the following imports:
`import 'package:ledger_web/src/ui/components/main_selection_bar.template.dart';` from ledger_web|lib/src/ui/components/service/main_selection_bar_service.dart at 7:1
`import 'package:ledger_web/src/ui/components/main_selection_bar.template.dart';` from ledger_web|lib/src/ui/components/service/main_selection_bar_service.template.dart at 11:1
... and more
It is correct to signal that there is not the import (MainSelectionBar is an angular component), because the template has not been generated.
Now the problem is, why the template is not there?
I checked the .dart_tool/build/generated directory but the template has not been created.
I have a similar package with a similar component that works fine, so I cannot figure out what's happened.
Is there a place where there is a more detailed error list?
Interestingly enough, there is also a case in which the template exists, but it is listed like if it was not found....
Any hint?
Most likely this is related to a build failure when generating the template, which is not being properly reported on subsequent builds. This pull request should help that https://github.com/dart-lang/build/pull/1834/, but you can also try running pub run build_runner clean and then doing a new build to get the original error back.

Can I use CoffeeScript to write my Electron (Atom Shell) application?

Does anything special have to be done to get Electron to run my main.coffee file? I have a main.js file (that works) that I converted to CoffeeScript (hence main.coffee), but when I run Electron main.coffee I get an error like the following:
App threw an error when running [SyntaxError: /Users/foo/develop/electron/main.coffee:13
app.on('window-all-closed', ->
^
Unexpected token >]
I can only assume this is a CoffeeScript issue, since when I commented the offending code with CoffeeScript's block comment (###), I got the following:
App threw an error when running [SyntaxError: /Users/foo/develop/electron/main.coffee:13
###
^
Unexpected token ILLEGAL]
I added coffee-script to my packages.json as a dependency, and made sure it was installed to my local node_modules directory like my other application dependencies, but that didn't seem to help.
I think, the main file main.js has to be javascript. But you can require a coffee file, for example application.coffee, from there using coffee-script.
main.js
// main.js
require('coffee-script').register();
require('./application')
application.coffee
# application.coffee
app = require('app')
BrowserWindow = require('browser-window')
# ...
Installing coffee-script
Include it in your package.json:
{
...
"devDependencies": {
"electron-prebuilt": "^0.33.1",
"coffee-script": "~1.10.0"
}
}
And run:
npm install
I've recently discovered that instead of transpiling to Javascript, you can do something like:
<script>
require('coffee-script').register();
require('../src/app/boot');
and then in src/app/boot.coffee you can use regular CoffeeScript :)
I found it in the app https://github.com/postcasio/hearthdash so there are more examples there.
There is no way to do it (atom doesn't ship with a coffeescript compiler), but you can use the watch option of coffeescript,
-w, --watch watch scripts for changes and rerun commands
For example:
coffee -w main.coffee in your case.

Typescript: unexpected reserved word in PHPStorm

I´m trying to get a simple TypeScript file working in PHPStorm, but sadly there seem to be some misconfiguration by default as the class keyword is not recognized properly
This is my TypeScript file:
class Test{
}
And this is the error I´m facing:
And this is my FieWatcher configuration of TypeScript
How can I get TypeScript working?
The Program options should not be node.exe (that would mean you are trying to typescript code as javascript). It needs to be tsc or node tsc(that means you want to run tsc to compile the file to javascript).
PS: this video might be helpful : https://www.youtube.com/watch?v=RWXGMug_Rmo&hd=1

my coffeescript file compiles but mocha gives an error

I have a project that uses "coffee-script": "^1.7.1" in its package.json.
The code has this line in it:
[{id: id, name: name}, ...] = result.rows
This compiles fine using coffeescript version 1.7.1
The problem is that I am trying to use mocha for unit tests and it gives me an error on this line:
Parse error on line xyz: Unexpected '...'
Apparently mocha uses an older coffeescript. Is there a way to make it work without adjusting the source for mocha?
EDIT:
my Gruntfile.coffee:
'use strict'
module.exports = ->
#initConfig
cafemocha:
src: ['test/*.coffee']
options:
reporter: 'spec'
ui: 'bdd'
coffee:
compile:
files:
'lib/mylib.js': ['src/*.coffee']
#loadNpmTasks 'grunt-cafe-mocha'
#loadNpmTasks 'grunt-contrib-coffee'
#registerTask 'default', ['coffee', 'cafemocha']
I added mocha.opts to the test directory:
--require coffee-script/register
--compilers coffee:coffee-script/register
--reporter spec
--ui bdd
but, still, when I run grunt, it gives me the same error. I am new to this environment, and I find it too complicated, please help.
Starting from version 1.7.x CoffeeScript compiler should be explicitly registered (see change log for version 1.7.0).
So, the problem is that CoffeeScript compiler is not registered when you're running your mocha tests, so node.js treats all your .coffee files as .js files.
The best possible solution is to specify --compilers option for your mocha tests:
--compilers coffee:coffee-script/register
If you don't want to include it to every mocha call, you could set it up using mocha.opts file.
Here are some useful links:
issue about it on github
reference in mocha docs
the reason behind this breaking change in CoffeeScript engine
Update
Looks like your issue is much deeper then I thought.
First, grunt-cafe-mocha doesn't respect mocha.opts because it's running tests by requireing mocha as a dependency, instead of calling mocha test runner.
So, it would've been enough to add require('coffee-script/register') to the top of your gruntfile, if not for this old grunt issue.
In short, grunt uses coffee-script 1.3.x, forcing all its tasks to use the same version of coffee. I had the same problem with grunt-contrib-connect, being unable to use latest coffee-script in my express app.
So, the only help I can offer you is a small grunt task I wrote to solve similar problem in one of my projects. It runs mocha in a separate child process, thus completely isolating it from grunt.
N.B. I had a thought about releasing this task to npm, but considered it too minor.