systemjs / builder

SystemJS build tool
MIT License
465 stars 122 forks source link

Cannot read 'moduleObj' of undefined #778

Closed tflori closed 7 years ago

tflori commented 7 years ago

I was debugging very long now - why there is no option to turn off uglyfing the code of builder?

I'm sure it's a problem of builder not of systemjs. I'm using SystemJS ^0.20 and SystemJS-Builder ^0.16. When importing from my app without using the bundle it works fine. When importing using the bundle I get this error:

TypeError: Cannot read property 'moduleObj' of undefined
    at eval (angular2-translator.js:1)
    at eval (TranslateService.ts:23)
    at l (angular2-translator.js:1)
    at eval (angular2-translator.js:1)
    at l (angular2-translator.js:1)
    at eval (angular2-translator.js:1)
    at l (angular2-translator.js:1)
    at f (angular2-translator.js:1)
    at eval (angular2-translator.js:1)
    at execute (format-helpers.js:126)
    at dynamicExecute (register-loader.js:678)
    at doEvaluate (register-loader.js:622)
    at ensureEvaluate (register-loader.js:531)
    at register-loader.js:551
    at Object.eval (module.ts:4)

I disabled minify and formatted the code then the error was more clear in this line:

return u = -1 === r.indexOf(d) ? a(d, d.linkRecord, r) : d.linkRecord.moduleObj, u.__useDefault ? u.default : u

To solve the issue I simply checked if d.linkRecord is truthy:

return u = -1 === r.indexOf(d) || !d.linkRecord ? a(d, d.linkRecord, r) : d.linkRecord.moduleObj, u.__useDefault ? u.default : u
arty-name commented 7 years ago

I am also seeing that after the upgrade to 0.20

guybedford commented 7 years ago

Is there any way either of you can provide a built bundle file and configuration that replicates this - would be great to look into it further.

arty-name commented 7 years ago

I will try to build a minimal demo, but it takes time, so maybe @tflori could make it quicker

tflori commented 7 years ago

yeah it's not so easy. you can check angular2-translator but I guess it is to big and you want smth like a small example. maybe I have time tomorrow

guybedford commented 7 years ago

Or just let me know the exact instructions to run a local build and test of angular2-translator if you can. It's just about getting an easy replication.

tflori commented 7 years ago

you can use npm run prepublish to build. there is a bundle.js that get's executed

Guy Bedford notifications@github.com schrieb am Do., 9. März 2017, 10:18:

Or just let me know the exact instructions to run a local build and test of angular2-translator if you can. It's just about getting an easy replication.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/systemjs/builder/issues/778#issuecomment-285297671, or mute the thread https://github.com/notifications/unsubscribe-auth/AEoXO-QTEkGg33uzNCAsVUHZrVQSgJs8ks5rj8P1gaJpZM4MTDSk .

guybedford commented 7 years ago

I'm getting these errors:

typings/globals/node/index.d.ts(1831,45): error TS2304: Cannot find name 'Iterable'.
typings/globals/node/index.d.ts(1845,10): error TS2304: Cannot find name 'Symbol'.

Let me know what I can do. Otherwise if you can just share the bundle and config and HTML file to execute them that demonstrates the issue that would avoid these issues.

tflori commented 7 years ago

I provided a plunkr with the same error by running node bundle.js in my project to create a bundle without the fix. hope that helps:

https://embed.plnkr.co/vibiPoIWmclXVPmwwbrR/

There is also a fixed version of the bundle inside. If you change to this in system.conf you see it's working

guybedford commented 7 years ago

@tflori thanks so much for the replication. I've included a fix in https://github.com/systemjs/builder/commit/cd19b07935b0042084c97ec2ca253bcd9c972aab, and verified this works against your case.

tflori commented 7 years ago

thanks, in which version we will get the fix?

Guy Bedford notifications@github.com schrieb am Do., 16. März 2017, 11:57:

@tflori https://github.com/tflori thanks so much for the replication. I've included a fix in cd19b07 https://github.com/systemjs/builder/commit/cd19b07935b0042084c97ec2ca253bcd9c972aab, and verified this works against your case.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/systemjs/builder/issues/778#issuecomment-287023265, or mute the thread https://github.com/notifications/unsubscribe-auth/AEoXO_kUnTBCwLmUx32jetWGdB4zW29Fks5rmRWEgaJpZM4MTDSk .

guybedford commented 7 years ago

Released in 0.16.4.