Open KellenHe opened 7 years ago
Hi, I had the same issue yesterday
Try to update your TypeScript dependency (should be ^2.4.0).
npm i --save typescript
For me it completely solved the problem.
@stas-kh Updading typescript dont fix error for me
@stas-kh Doesn't work!
Here are the steps that helped me yesterday to solve the problem:
npm install typescript@latest --save
npm install
@stas-kh Thanks! It worked for me.
The angular-cli loads the typescript package into dev-dependencies. Why do we create another dependency with the command
npm install typescript@latest --save?
@swimlane/ngx-datatable why can't it do?
I found the previous ngx-datatable version
the enum code like this:
export enum ClickType {
single = 'single' as any,
double = 'double' as any
}
it worked normal.
I tried all above but it is still not working :(
I have the same issue. It is a problem with ClickType, ColumnMode, SortType, ContextMenu, SelectionType and possible others. The solution from @KellenHe did not work for me.
Hello ! Same problem here
Update: after a restart, update typescript did the trick ! Thanks
Thanks @stas-kh you pointed me in the right direction and things are up and running again for me.
That said I just used npm install typescript@latest --save-dev
to avoid the additional dependency
I just got the issue today. So we have to upgrade typescript? This feels like too much magic.............
also using the latest typescript did not work for me :cry:
update: I've decided that I like this library, and want to show it off to others, so I'm going to take a crack at creating a patch to fix this problem
seems like the issue was reported here as well: https://github.com/swimlane/ngx-ui/issues/95
an example of the error is here: https://github.com/Microsoft/TypeScript/blob/master/tests/baselines/reference/ambientErrors.errors.txt#L50-L55
// Ambient enum with computer member
declare enum E2 {
x = 'foo'.length
~~~~~~~~~~~~
// !!! error TS1066: In ambient enum declarations member initializer must be constant expression.
}
the trouble-maker files:
It looks like all enums have this same issue?
Reported the issue to TypeScript to see if it's an issue on their end in their latest releases: https://github.com/Microsoft/TypeScript/issues/18189
tested this at home, with a separate repo to see if TypeScript was the issue, both 2.4.2 and 2.5.x work correctly, no compilation errors. so I'm starting to assume this is a problem with angular-cli's particular configuration.
funny story, I was able to replicate this issue in a project that isn't using ngx-datatable at all!
this was the code:
export declare enum State {
initial = "initial",
final = "final",
};
Error was:
ERROR in /home/rudolfo/Code/angular-animations-sandbox/src/app/animations.ts (4,15): In ambient enum declarations member initializer must be constant expression.
should be easier to debug this and it's definitely an issue with angular-cli.
welp I figured it out, angular-cli is stuck at version 2.3.4, the generated package.json has these lines:
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
Version 2.3.4 shows the error, upgrading typescript to "~2.4.0"
or "^2.4.0"
almost fixes the issue. When you upgrade typescript to the latest and run it on its own with $(npm bin)/tsc
it will compile and not output any error message. However if you run ng build
it will still fail as if it is running the older version of typescript.
I believe upgrading to typescript latest version is not the fix. I am using angular 4.3.4 and it's not compatible with typescript version >= 2.4 So I can't upgrade to latest typescript version.
I'm getting same error
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (3,13): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/column-mode.type.d.ts (2,16): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/column-mode.type.d.ts (4,13): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/sort.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/sort.type.d.ts (3,13): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/sort-direction.type.d.ts (2,11): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/sort-direction.type.d.ts (3,12): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/column-mode.type.d.ts (3,12): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (4,18): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (5,12): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (6,16): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/click.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/click.type.d.ts (3,14): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/contextmenu.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in C:/Pratap/CB_Code/cb-dashboard/node_modules/@swimlane/ngx-datatable/release/types/contextmenu.type.d.ts (3,12): In ambient enum declarations member initializer must be constant expression.
@pratapgowda007 I am on Angular 4.3.3 with TS 2.4.2 and no problems. I would be surprised if you couldn't upgrade TS on Angular 4.3.4
@Confusedfish are you using angular-cli or some other seed project, are you using webpack or rollup? It looks like the issue with the typescript version depends on which plugins/buildsystem/seed/boilerplate system is used.
@omouse I have been using angular-cli, although I have upgraded TS manually as the project is older than the current version of angular-cli so perhaps this problem isn't a problem with the latest release?
Let me know if I can help test in some way
@Confusedfish if your code is free/open source licensed could you link to it or paste it on gist.github.com and if it isn't, can you at least paste the package.json and your tsconfig (the one that is used by angular-cli) and which version of angular-cli you are using?
thank you!
ng --version
@angular/cli: 1.3.2 node: 6.9.1 os: win32 x64 @angular/animations: 4.3.3 @angular/common: 4.3.3 @angular/compiler: 4.3.3 @angular/core: 4.3.3 @angular/forms: 4.3.3 @angular/http: 4.3.3 @angular/platform-browser: 4.3.3 @angular/platform-browser-dynamic: 4.3.3 @angular/router: 4.3.3 @angular/cli: 1.3.2 @angular/compiler-cli: 4.3.3 @angular/language-service: 4.3.6
angular-cli.json:
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "project": { "name": "" }, "apps": [ { "root": "src", "outDir": "wwwroot", "assets": [ "assets", "favicon.ico" ], "index": "index.html", "main": "main.ts", "polyfills": "polyfills.ts", "test": "test.ts", "tsconfig": "tsconfig.app.json", "testTsconfig": "tsconfig.spec.json", "prefix": "app", "styles": [ "styles.scss" ], "scripts": [], "environmentSource": "environments/environment.ts", "environments": { "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts", "test": "environments/environment.test.ts" } } ], "e2e": { "protractor": { "config": "./protractor.conf.js" } }, "lint": [ { "project": "src/tsconfig.app.json", "exclude": "**/node_modules/**" }, { "project": "src/tsconfig.spec.json", "exclude": "**/node_modules/**" }, { "project": "e2e/tsconfig.e2e.json", "exclude": "**/node_modules/**" } ], "test": { "karma": { "config": "./karma.conf.js" } }, "defaults": { "styleExt": "scss", "component": {} } }
packages.json:
{ "name": "", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build --prod --aot", "build.test": "ng build --prod --aot --environment=test", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "^4.3.3", "@angular/common": "^4.3.3", "@angular/compiler": "^4.3.3", "@angular/core": "^4.3.3", "@angular/forms": "^4.3.3", "@angular/http": "^4.3.3", "@angular/platform-browser": "^4.3.3", "@angular/platform-browser-dynamic": "^4.3.3", "@angular/router": "^4.3.3", "@ngrx/effects": "^4.0.5", "@ngrx/router-store": "^4.0.4", "@ngrx/store": "^4.0.3", "@ngrx/store-devtools": "^4.0.0", "@swimlane/ngx-datatable": "^10.1.0", "@types/adal": "^1.0.28", "adal-angular": "^1.0.15", "core-js": "^2.4.1", "font-awesome": "^4.7.0", "ngx-bootstrap": "^1.9.1", "ngx-uploader": "^3.3.9", "rxjs": "^5.4.1", "zone.js": "^0.8.14" }, "devDependencies": { "@angular/cli": "^1.3.2", "@angular/compiler-cli": "^4.3.3", "@angular/language-service": "^4.3.6", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", "codelyzer": "~3.0.1", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": "~4.1.0", "karma": "~1.7.0", "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.1.2", "ts-node": "~3.0.4", "tslint": "~5.3.2", "typescript": "^2.4.2" } }
I can confirm that by generating a blank app using ng new testapp
, adding ngx-datatables with npm install @swimlane/ngx-datatable@latest --save
adding the import to app.module then you will get the reported error when you ng build
you will get lots of In ambient enum declarations member initializer must be constant expression.
Running npm install typescript@latest --save-dev
(note the use of --save-dev not --save) bumps the typescript version but there is a conflict with the version of typescript linked by @angular-cli@1.3.2
because typescript has now jumped to 2.5.2. Perhaps this isn't an issue with the latest CLI.
+-- @ angular/cli@ 1.3.2 | -- typescript@ 2.4.2 -- typescript@ 2.5.2
npm install typescript@2.4.2 --save-dev
will avoid the conflict and ng build
will compile as expected.
Upgrading from Angular 4.2.4 to 4.3.4:
npm install @angular/core@4.3.4 @angular/animations@4.3.4 @angular/common@4.3.4 @angular/compiler@4.3.4 @angular/forms@4.3.4 @angular/http@4.3.4 @angular/platform-browser@4.3.4 @angular/platform-browser-dynamic@4.3.4 @angular/router@4.3.4 --save
npm install @angular/compiler-cli@4.3.4 @angular/language-service@4.3.4 --save-dev
and ng build
still raises no errors.
I hope the above is helpful to someone.
@Confusedfish so it is a problem with angular-cli then because it doesn't use the project-specific version of typescript?
Thank you so much for trying it out and replicating the error! 💯 🥇
@omouse I don't understand how this can be closed? Angular 2+ doesn't yet support 2.4.x Typescript (until Angular 5), so this completely prevents use of this component until Angular 5 in a stable Angular environment. Whats happening here?
@jonathanbarton I am currently on Angular 4.4.4 using Typescript 2.5.3 and ngx-datatable 10.2.3 without problems other than a little nag about the TS version when compiling.
@jonathanbarton the angular-cli issue that i opened was closed by their team, the issue definitely remains open and I've moved away from using angular-cli and the other 'seed' projects because they don't consistently work with ngx-datatable.
Wow, thanks for the answers guys. I think I might be stuck because upgrading to 4.x is going to break some other deps in our project. But this is good to clarify...thanks! -J
https://github.com/angular/angular-cli/issues/7578#issuecomment-329536604
CLI version 1.3 only supports up to TS 2.4. You'll need to use CLI 1.4 or higher to support TS 2.5.
Has anyone tried upgrading to CLI 1.4?
But angular/compiler also complains if you use version greater (or equal to) than 2.5.0
I don't understand why this project is on ts 2.5 considering even angular5 has said stay on ts 2.4
Thank you @Confusedfish Its worked for me.
I'm submitting a ... (check one with "x")
Current behavior when i build, these are some typescript errors: ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/column-mode.type.d.ts (2,16): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/column-mode.type.d.ts (3,12): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/column-mode.type.d.ts (4,13): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/sort.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/sort.type.d.ts (3,13): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/sort-direction.type.d.ts (2,11): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/sort-direction.type.d.ts (3,12): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (3,13): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (4,18): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (5,12): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/selection.type.d.ts (6,16): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/click.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/click.type.d.ts (3,14): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/contextmenu.type.d.ts (2,14): In ambient enum declarations member initializer must be constant expression.
ERROR in E:/works/ferrari-update/ferrari/Grand/node_modules/@swimlane/ngx-datatable/release/types/contextmenu.type.d.ts (3,12): In ambient enum declarations member initializer must be constant expression.
Expected behavior build normal
Reproduction of the problem
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
Table version: 0.8.x
Angular version: 2.0.x
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Language: [all | TypeScript X.X | ES6/7 | ES5]