firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Nativescript 8 error TypeError: Cannot read property 'env' of undefined

Open msureshmewara opened this issue 1 year ago • 7 comments

Operating System

14.1.1 (23B81)

Browser Version

601

Firebase SDK Version

10.1.0

Firebase SDK Product:

Firestore

Describe your project's tooling

Restarting application on device emulator-5554... System.err: An uncaught Exception occurred on "main" thread. System.err: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function System.err: TypeError: Cannot read property 'env' of undefined System.err: File: (file: src/webpack:/june_5/webpack/bootstrap:27:0) System.err: System.err: StackTrace: System.err: ./node_modules/@grpc/grpc-js/build/src/logging.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/logging.js:37:43) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/metadata.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/metadata.js:20:18) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/call-credentials.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/call-credentials.js:20:19) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/index.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/index.js:20:27) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@firebase/firestore/dist/index.node.mjs(file:///data/data/org.nativescript.june5/files/app/vendor.js:97233:71) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/item/items.component.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:341:77) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/app-routing.module.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:184:79) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/app.module.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:239:77) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/main.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:34:73) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at webpack_exec(file:///data/data/org.nativescript.june5/files/app/bundle.js:525:39) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:526:189) System.err: at webpack_require.X(file: src/webpack:/june_5/webpack/runtime/startup entrypoint:6:0) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:526:47) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:531:3) System.err: at require(:1:266) System.err: System.err: System.err: TypeError: Cannot read property 'env' of undefined System.err: System.err: StackTrace: System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function System.err: TypeError: Cannot read property 'env' of undefined System.err: File: (file: src/webpack:/june_5/webpack/bootstrap:27:0) System.err: System.err: StackTrace: System.err: ./node_modules/@grpc/grpc-js/build/src/logging.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/logging.js:37:43) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/metadata.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/metadata.js:20:18) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/call-credentials.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/call-credentials.js:20:19) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/index.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/index.js:20:27) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@firebase/firestore/dist/index.node.mjs(file:///data/data/org.nativescript.june5/files/app/vendor.js:97233:71) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/item/items.component.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:341:77) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/app-routing.module.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:184:79) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/app.module.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:239:77) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/main.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:34:73) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at webpack_exec(file:///data/data/org.nativescript.june5/files/app/bundle.js:525:39) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:526:189) System.err: at webpack_require.X(file: src/webpack:/june_5/webpack/runtime/startup entrypoint:6:0) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:526:47) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:531:3) System.err: at require(:1:266) System.err: System.err: System.err: TypeError: Cannot read property 'env' of undefined System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6717) System.err: at android.app.ActivityThread.access$1300(ActivityThread.java:237) System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913) System.err: at android.os.Handler.dispatchMessage(Handler.java:106) System.err: at android.os.Looper.loop(Looper.java:223) System.err: at android.app.ActivityThread.main(ActivityThread.java:7656) System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) System.err: Caused by: com.tns.NativeScriptException: Error calling module function System.err: TypeError: Cannot read property 'env' of undefined System.err: File: (file: src/webpack:/june_5/webpack/bootstrap:27:0) System.err: System.err: StackTrace: System.err: ./node_modules/@grpc/grpc-js/build/src/logging.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/logging.js:37:43) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/metadata.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/metadata.js:20:18) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/call-credentials.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/call-credentials.js:20:19) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@grpc/grpc-js/build/src/index.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/index.js:20:27) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./node_modules/@firebase/firestore/dist/index.node.mjs(file:///data/data/org.nativescript.june5/files/app/vendor.js:97233:71) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/item/items.component.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:341:77) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/app-routing.module.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:184:79) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/app/app.module.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:239:77) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at fn(file: src/webpack:/june_5/webpack/runtime/hot module replacement:61:0) System.err: at ./src/main.ts(file:///data/data/org.nativescript.june5/files/app/bundle.js:34:73) System.err: at webpack_require(file: src/webpack:/june_5/webpack/bootstrap:24:0) System.err: at webpack_exec(file:///data/data/org.nativescript.june5/files/app/bundle.js:525:39) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:526:189) System.err: at webpack_require.X(file: src/webpack:/june_5/webpack/runtime/startup entrypoint:6:0) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:526:47) System.err: at (file:///data/data/org.nativescript.june5/files/app/bundle.js:531:3) System.err: at require(:1:266) System.err: System.err: System.err: TypeError: Cannot read property 'env' of undefined System.err: at com.tns.Runtime.runModule(Native Method) System.err: at com.tns.Runtime.runModule(Runtime.java:689) System.err: at com.tns.Runtime.run(Runtime.java:681) System.err: at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21) System.err: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192) System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712) System.err: ... 8 more Successfully synced application org.nativescript.june5 on device emulator-5554.

Describe the problem

{ "name": "june_5", "main": "./src/main.ts", "version": "1.0.0", "private": true, "dependencies": { "@angular/animations": "~12.0.0", "@angular/common": "~12.0.0", "@angular/compiler": "~12.0.0", "@angular/core": "~12.0.0", "@angular/forms": "~12.0.0", "@angular/platform-browser": "~12.0.0", "@angular/platform-browser-dynamic": "~12.0.0", "@angular/router": "~12.0.0",

"@grpc/grpc-js": "^1.10.9",
"@grpc/proto-loader": "^0.7.13",
"@nativescript-community/ui-drawer": "0.0.30",
"@nativescript-community/ui-material-bottomnavigationbar": "^6.2.14",
"@nativescript-community/ui-material-bottomsheet": "^6.2.23",
"@nativescript/angular": "~12.0.0",
"@nativescript/appversion": "^2.0.0",
"@nativescript/core": "~8.0.0",
"@nativescript/datetimepicker": "~2.1.6",
"@nativescript/localize": "5.0.4",
"@nativescript/picker": "4.0.0",
"@nativescript/secure-storage": "3.0.0",
"@nativescript/theme": "~3.0.1",
"@nativescript/unit-test-runner": "^2.0.5",
"@ngrx/effects": "12.4.0",
"@ngrx/store": "12.4.0",
"@ngx-translate/core": "13.0.0",
"@ngx-translate/http-loader": "6.0.0",
"@nstudio/nativescript-cardview": "2.0.1",
"@nstudio/nativescript-checkbox": "2.0.4",
"@nstudio/nativescript-snackbar": "^2.1.0",
"@types/country-list": "2.1.0",
"countries-list": "2.6.1",
"country-flag-icons": "1.4.10",
"firebase": "^10.12.2",
"loadsh": "0.0.4",
"nativescript-dna-deviceinfo": "3.7.1",
"nativescript-iqkeyboardmanager": "1.5.1",
"nativescript-numeric-keyboard": "5.0.2",
"nativescript-radiobutton": "0.1.0",
"nativescript-sqlite": "2.8.5",
"nativescript-ui-listview": "10.0.1",
"nativescript-windowed-modal": "^7.0.0",
"ngx-infinite-scroll": "10.0.1",
"node-fetch": "2.7.0",
"node-polyfill-webpack-plugin": "^4.0.0",
"qs": "npm:querystring@^0.2.1",
"rxjs": "6.6.0",
"sass": "~1.49.9",
"util": "^0.10.0",
"zone.js": "~0.11.4"

}, "devDependencies": { "@angular/compiler-cli": "~12.0.0", "@angular-devkit/build-angular": "~12.1.2", "@nativescript/android": "8.1.1", "@nativescript/ios": "8.3.3", "@nativescript/types": "~8.0.0", "@nativescript/webpack": "5.0.21", "@ngtools/webpack": "12.1.4", "@types/jasmine": "3.9.1", "karma": "6.3.9", "karma-jasmine": "4.0.1", "karma-nativescript-launcher": "0.4.0", "karma-webpack": "5.0.0", "babel-cli": "^6.26.0", "babel-plugin-transform-class-properties": "^6.24.1", "babel-preset-env": "^1.6.1", "typescript": "4.2.3" }, "readme": "NativeScript Application", "ignoreMissingDependencies": "true" }

Steps and code to reproduce issue

Create a Nativescript version 8 or above Application. install - npm install firebase. //intilize the SDK this.app = initializeApp(this.firebaseConfig);

Then call the below function const db = getFirestore(this.app);

msureshmewara avatar Jun 19 '24 20:06 msureshmewara

Hi @msureshmewara,

It looks like the error originates in File: (file: src/webpack:/june_5/webpack/bootstrap:27:0). Any chance you know what that line is doing?

DellaBitta avatar Jun 20 '24 22:06 DellaBitta

@DellaBitta : "@nativescript/webpack": "5.0.21", - Its a webpack file

msureshmewara avatar Jun 20 '24 23:06 msureshmewara

Perhaps this is where it's complaining about?

System.err: ./node_modules/@grpc/grpc-js/build/src/logging.js(file: src/webpack:/june_5/node_modules/@grpc/grpc-js/build/src/logging.js:37:43)

Can you check node_modules/@grpc/grpc-js/build/src/logging.js:37:43 and let us know what it is?

The closest thing I can find is this, and if that's giving you Cannot read property 'env' of undefined, it means that process was undefined for some reason. (this code in grpc has been there for 3 years, and I doubt it's the culprit).

ehsannas avatar Jun 21 '24 21:06 ehsannas

@ehsannas : Process.env - process is always undefined.

const verbosityString = process.env.GRPC_NODE_VERBOSITY ?? process.env.GRPC_VERBOSITY ?? '';

msureshmewara avatar Jun 24 '24 12:06 msureshmewara

Hi @msureshmewara,

This looks to be an error in the build process of your application. It appears that the bundler is bringing in the Node.js version of the Firebase SDK but then executing the build in a non-node environment. You'll need to do some debugging of your app's build pipeline to determine why that might be the case.

DellaBitta avatar Jun 24 '24 19:06 DellaBitta

@DellaBitta : Thank you :), The error occurs only when I am trying to initialize the firebase/firestore.

initializeApp(this.firebaseConfig); // This function is working fine.

getFirestore(this.app); // Once we call this getting the above error.

msureshmewara avatar Jun 25 '24 16:06 msureshmewara

I understand, but it appears that the build pipeline is bringing in the node version of Firestore when it shouldn't be.

DellaBitta avatar Jun 25 '24 18:06 DellaBitta

Hey @msureshmewara. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jul 09 '24 01:07 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@msureshmewara if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Jul 16 '24 01:07 google-oss-bot