thiagobustamante / typescript-ioc

A Lightweight annotation-based dependency injection container for typescript.
MIT License
526 stars 64 forks source link

Production build ends with error: SyntaxError: Unexpected token: name (isBrowser) #7

Closed drwatson1 closed 7 years ago

drwatson1 commented 7 years ago

Steps to reproduce are the same as I described some time ago in issue #6 from step 1 to 3. After that run this in command line: npm run build and you'll get an error:

> react-scripts-ts build

Creating an optimized production build...
ts-loader: Using typescript@2.3.3 and D:\GitHub\efforts\efforts-frontend\tsconfig.json
Failed to compile.

static/js/main.b2af2918.js from UglifyJs
SyntaxError: Unexpected token: name (isBrowser) [./~/typescript-ioc/index.js:3,0]
thiagobustamante commented 7 years ago

I tried the steps and I received another similar error message:

static/js/main.f4808811.js from UglifyJs
Unexpected token: name (construct) [./~/typescript-ioc/es6.js:26,0][static/js/main.f4808811.js:23017,4]

I could not identify what is exactly the problem, but it looks related to some UglifyJS task when analysing ES6 syntax.

I forced the usage of ES5 versions and the error disappeared to me.

import { Container } from 'typescript-ioc/es5';
Container.bind(Date).to(Date);

It works, once the generated project uses "target": "es5", on tsconfig.json.

drwatson1 commented 7 years ago

I found this answer from create-react-app contributor. External dependencies with es6 syntax is not supported. Thus I think it is not your issue and you can close it.