Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Builder fails silently once typescript is updated to 2.3.1+ #828

Open
jamesbrobb opened this issue Jul 29, 2017 · 5 comments
Open

Builder fails silently once typescript is updated to 2.3.1+ #828

jamesbrobb opened this issue Jul 29, 2017 · 5 comments

Comments

@jamesbrobb
Copy link

jamesbrobb commented Jul 29, 2017

Versions

systemjs-builder: 0.16.9 (also tested and confirmed with 0.15.34)
typescript: 2.3.1+ (the issue does not exist with 2.3.0)

Issue

Yesterday i updated a project to typescript 2.4.2 (from 2.2.2) and my gulp build script started to fail silently. I've recreated a bare bones, minimal recreation of the issue here:

https://github.com/jamesbrobb/systemjs-builder-typescript-2.3.1--issue

So far i've managed to trace it to this point:

https://github.com/systemjs/builder/blob/master/lib/trace.js#L509

But i'm struggling to work out which bit of code actually gets called by loader.translate to determine where the actual failure occurs? I'll continue to see if i can debug it further to work out the source of the issue.

@jamesbrobb
Copy link
Author

I've tracked the issue down to here (as this verion of systemjs-builder currently uses systemjs 0.19.47):

https://github.com/systemjs/systemjs/blob/0.19.47/dist/system.src.js#L3544

It looks like something has changed in typescript 2.3.1 which means that it's now detected as esm by the esmRegEx. So the if block on line 3544 gets run, which in turn causes the builder to silently fail.

I've forced the typescript source to not be detected as esm in my local version and everything works correctly and the build completes and outputs the file. But i'm afraid fixing the regex (or what's expected from it) is a bit beyond me.

Took a while to work out, but at least this made me smile ;)

good enough ES6 module detection regex - format detections not designed to be accurate, but to handle the 99% use case

@aluanhaddad
Copy link

Use package or meta configuration to target typescript and specify format: "cjs". The better solution though is to use plugin-typescript.

@jamesbrobb
Copy link
Author

jamesbrobb commented Jul 29, 2017

@aluanhaddad thanks for the quick response.

Unfortunately setting the format to cjs (in either packages or meta) results in the following error:

{ Error on translate for main at file:///Users/blah/blah/project/src/main.ts
        (SystemJS) ENOENT: no such file or directory, open '/Users/blah/blah/project/src/fs'
        Error: ENOENT: no such file or directory, open '/Users/blah/blah/project/src/fs'
            at Error (native)
        Error loading /Users/blah/blah/project/src/fs as "fs" from /Users/blah/blah/project/node_modules/typescript/lib/typescript.js
        Unable to load transpiler to transpile /Users/blah/blah/project/src/main.ts
  originalErr: 
   { Error: ENOENT: no such file or directory, open '/Users/blah/blah/project/src/fs'
       at Error (native)
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/Users/blah/blah/project/src/fs' } }

@jamesbrobb
Copy link
Author

Installing and configuring plugin-typescript fixed the issue, thanks

@aluanhaddad
Copy link

Yeah I forgot all of the other configuration that you need to add in addition to format.

plugin-typescript helps handle that.

I'm glad you got it working and I hope others find this discussion useful.

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

No branches or pull requests

2 participants