Nativescript-plugin-firebase: error TS1036: Statements are not allowed in ambient contexts

Created on 25 Apr 2018  ·  20Comments  ·  Source: EddyVerbruggen/nativescript-plugin-firebase

Hi,

I'm having an issue when i'm trying to start my nativescript project. It happens every time just after I add firebase plugin to my app.

Executing before-prepare hook from /home/flow/nativescript/real/t/app/ChallengeMeApp/hooks/before-prepare/nativescript-dev-typescript.js Found peer TypeScript 2.6.2 node_modules/nativescript-plugin-firebase/firebase.d.ts(699,1): error TS1036: Statements are not allowed in ambient contexts.

Here is my package.json

{
"description": "NativeScript Application",
"license": "SEE LICENSE IN ",
"readme": "NativeScript Application",
"repository": "",
"nativescript": {
"id": "com.teeme.challengemeapp",
"tns-android": {
"version": "3.4.2"
}
},
"scripts": {
"lint": "tslint "app/*/.ts""
},
"dependencies": {
" @ angular/animations": "~5.2.0",
" @ angular/common": "~5.2.0",
" @ angular/compiler": "~5.2.0",
" @ angular/core": "~5.2.0",
" @ angular/forms": "~5.2.0",
" @ angular/http": "~5.2.0",
" @ angular/platform-browser": "~5.2.0",
" @ angular/platform-browser-dynamic": "~5.2.0",
" @ angular/router": "~5.2.0",
"font-awesome": "^4.7.0",
"nativescript-angular": "^5.3.0",
"nativescript-camera": "^4.0.2",
"nativescript-imagepicker": "^6.0.1",
"nativescript-plugin-firebase": "^5.2.0",
"nativescript-pulltorefresh": "^2.1.0",
"nativescript-snackbar": "^3.0.0",
"nativescript-theme-core": "^1.0.4",
"nativescript-toast": "^1.4.6",
"nativescript-ui-listview": "^3.5.4",
"reflect-metadata": "~0.1.10",
"rxjs": "~5.5.5",
"tns-core-modules": "^4.0.0",
"zone.js": "~0.8.18"
},
"devDependencies": {
"@angular/compiler-cli": "~5.2.0",
"@ngtools/webpack": "~1.9.4",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"codelyzer": "~4.0.2",
"copy-webpack-plugin": "~4.3.0",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
"nativescript-dev-sass": "~1.3.5",
"nativescript-dev-typescript": "~0.6.0",
"nativescript-dev-webpack": "~0.9.1",
"nativescript-worker-loader": "~0.8.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.2.1",
"sass-loader": "~6.0.6",
"tslint": "~5.8.0",
"typescript": "~2.6.2",
"uglifyjs-webpack-plugin": "~1.1.6",
"webpack": "~3.10.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "~1.1.0"
}
}

I already did things like linking with firebase, init firebase when app starting...

Most helpful comment

Should be fine now.

All 20 comments

You can pin to the 5.2.0 version for now to avoid that issue.

Can you try removing the semicolon on this line?

And if that doesn't help, please share your project because I can't reproduce it.

Hi,

Thanks for your quick answer !
I tried switching 5.2.0, same error.
Also try to remove the semicolon but nothing.

I tried to run
`
npm install

npm WARN [email protected] requires a peer of tns-core-modules@^3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
`

Not sure if it can be the problem ?

Here is the link for my project : https://github.com/Nazort/app

Thanks. Did you try using “5.2.0” instead of “^5.2.0”?

I’ll clone and run your repo tomorrow.

I just tried but it's the same.

Thank you for your time.

I appreciate the attempt, but the erroring line of code in firebase.d.ts is 699 in your stacktrace. That file has changes significantly between 5.2.0 and 5.3.0 so please make sure you test both versions and compare the errors. It's crucial for us figuring out how to fix this :)

Our build broke on that same line with 5.3.0 (dependency was set to ^5.2.0 so it picked 5.3.0 after clean install)

node_modules/nativescript-plugin-firebase/firebase.d.ts(699,1): error TS1036: Statements are not allowed in ambient contexts.

First though was that it's due to AoT / webpack compilation but the same happens on a plain tns build android

After cleaning (rm node_modules, hooks, platforms) and pinning nativescript-plugin-firebase to 5.2.0 it compiles just fine.

After upgrading nativescript and core modules, Typescript to the latest versions, and firebase plugin to 5.3.0 i started getting this error. Cleaning node-modules, hooks, and platforms, and then pinning to 5.2.0 solved the problem.

Can anyone suggest a fix?

my bet would be that the statement/assignment
exports.analytics = analytics;
is causing the trouble as d.ts files may only contain declarations but not implementations. Maybe you could do the export somewhere else?

or maybe you could just do this in firebase.d.ts?
export * from './analytics';

@lambourn I wonder if you would still have code completion.. can you change the file in node_modules and see that a) the error is gone, and b) code completion works?

Please don't pollute this important issue with other questions. You already asked in #370.

@EddyVerbruggen I just tried this and code hinting in VS Code does work.

in node_modules/nativescript-plugin-firebase/firebase.d.ts I changed 698-699 to
export * from './analytics';

in my .ts file I did

import * as firebase from "nativescript-plugin-firebase";

const foo: firebase.LogEventOptions = {key: "foo"};
firebase.logEvent(foo);

it compiles fine and I get proper code hinting. From my point of view this is working as expected.

Ok, I will also try this tonight.

@lambourn Funny, I tried that one as well but IntelliJ didn't seem to pick up the typings. I'll give it another shot.

@EddyVerbruggen hmm. I just tried it with WebStorm which I think uses the IntelliJ core and it works there as well (I am on macOS btw if that matters)

@lambourn That sounds hopeful. Not found the time yet to try it but I will.

@lambourn Oh now I see what the difference is; you're doing firebase.logEvent(foo); while I want it to be firebase.analytics.logEvent(foo); for backward compatibility. Thoughts?

Also, I wonder why I don't get this error with TS 2.4, 2.6, nor 2.8. Could it be our tsconfig's or reference.d.ts files are different?

Should be fine now.

Was this page helpful?
0 / 5 - 0 ratings