Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

es6 compile errors with no location information #24

Closed
arolson101 opened this issue Nov 2, 2015 · 14 comments
Closed

es6 compile errors with no location information #24

arolson101 opened this issue Nov 2, 2015 · 14 comments

Comments

@arolson101
Copy link

I'm trying to switch over to the latest typescript so that I can use async/await inside a mocha test. My tsconfig specifies es6 and module commonjs. If I run tsc from the command-line it reports no errors, but when I run from gulp (which registers ts-node) I get this error.

[15:15:17] Using gulpfile C:\updraft\Gulpfile.js
[15:15:17] Starting 'test'...
[15:15:20] 'test' errored after 3.03 s
[15:15:20] SyntaxError in plugin 'gulp-mocha'
Message:
    Block-scoped declarations (let, const, function, class) not yet supported outside strict mode Stack:
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.loader (C:\updraft\node_modules\ts-node\dist\ts-node.js:102:18)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (C:\updraft\src\index.ts:1:20)
    at Module._compile (module.js:434:26)
    at Object.loader (C:\updraft\node_modules\ts-node\dist\ts-node.js:102:18)

So problem (1) is that there shouldn't be a difference between tsc and ts-node (I have typescript@next installed locally and globally), and (2) is that the output gives no indication of where (file/line) the error was found

@blakeembrey
Copy link
Member

You need to use gulpfile.ts. It's using gulpfile.js above.

Edit: Make sure you don't have both - .js will resolve before .ts.
Edit 2: That error is also from node, not from TypeScript or ts-node.

@arolson101
Copy link
Author

I set up a gulpfile.js to load my renamed gulpfile.ts using the instructions here (substituting typescript-register with ts-node/register) but the error remains the same.

Is there a guide for how to use ts-node with gulp?

@blakeembrey
Copy link
Member

No guide. You just create a gulpfile.ts and have ts-node installed. It works automatically. Do you have a project you can share with this? Do you have a tsconfig.json file at all?

@arolson101
Copy link
Author

yep, that worked. All is good. You should put a note about using Gulpfile.ts in your readme.md

@arolson101
Copy link
Author

I spoke too soon; I had forgotten to redo the es6/await changes in my test. I'm still getting

[19:16:38] Requiring external module ts-node/register
[19:16:45] Using gulpfile ~/Developer/updraft/Gulpfile.ts
[19:16:45] Starting 'test'...
[19:16:48] 'test' errored after 2.63 s
[19:16:48] SyntaxError in plugin 'gulp-mocha'
Message:
    Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
Stack:
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.loader (/Users/aolson/Developer/updraft/node_modules/ts-node/dist/ts-node.js:102:18)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/aolson/Developer/updraft/src/index.ts:1:20)
    at Module._compile (module.js:434:26)
    at Object.loader (/Users/aolson/Developer/updraft/node_modules/ts-node/dist/ts-node.js:102:18)

@arolson101
Copy link
Author

I do have a tsconfig.json
I've published my changes here: https://github.com/arolson101/updraft/tree/changelog

@blakeembrey
Copy link
Member

@arolson101 You're compiling to ES6. Set it to es5 (https://github.com/arolson101/updraft/blob/changelog/tsconfig.json#L4).

@blakeembrey
Copy link
Member

But that won't work because you're using [edit: certain] ES6 features, so what you should do is what the directions say. 'use strict' in your file.

@arolson101
Copy link
Author

But which file? And why does it compile fine under tsc but not ts-node?

-ARO

On Nov 2, 2015, at 7:29 PM, Blake Embrey [email protected] wrote:

But that won't work because you're using ES6 features, so what you should do is what the directions say. 'use strict' in your file.


Reply to this email directly or view it on GitHub.

@blakeembrey
Copy link
Member

It does compile using ts-node. As I've said, that's an error from node.

Edit: ts-node does not output any SyntaxErrors, those are JS issues. This module formats the errors with line/numbers like in the README.

@blakeembrey
Copy link
Member

The issue is you're compiling to ES6 in tsconfig.json (which ts-node uses) and node does not support the ES6 output yet - hence "block-scoped declarations (let, const, function, class) not yet supported outside strict mode".

@arolson101
Copy link
Author

arolson101 commented Nov 3, 2015 via email

@blakeembrey
Copy link
Member

No worries, I'll add some docs on node/gulp/typescript interop when I have a chance - just made an issue to track that. You should be able to use multiple tsconfig.json files too, or move tsconfig.json away from the CWD to avoid it loading automatically (neither are great fixes, but that's an issue when we have a lot of tools consuming the same file).

@arolson101
Copy link
Author

Looking around the web, it seems that normally nodejs would report the line that has the problem; this is what ts-node is not doing. For example:

http.createServer(app).listen(app.get('port'), function(){
^^^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:929:3

ts-node is missing the line & error indicators. For instance:

[21:58:17] SyntaxError in plugin 'gulp-mocha'
Message:
    Unexpected identifier
Stack:
SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.loader (/Users/aolson/Developer/updraft/node_modules/ts-node/dist/ts-node.js:103:18)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /Users/aolson/Developer/updraft/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/aolson/Developer/updraft/node_modules/mocha/lib/mocha.js:213:14)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants