Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: NativeScriptViewFactory is not defined on iOS built with mode --release. #10519

Open
3 tasks done
paulmlilo opened this issue Apr 15, 2024 · 18 comments
Open
3 tasks done

Comments

@paulmlilo
Copy link

paulmlilo commented Apr 15, 2024

Issue Description

Nativescript version: 8.7.1
Environment: iOS 17.4.1
Build: Release

When I build the app for iOS in --release mode, the app crashes on launch with a Fatal error
***** Fatal JavaScript exception - application has been terminated. *****
NativeScript encountered a fatal error:

Uncaught ReferenceError: NativeScriptViewFactory is not defined

Screenshot 2024-04-15 at 15 58 36

Reproduction

  • Upgrade or install Nativescript 8.7.0 with angular.
  • run ns run ios --bundle --release

Relevant log output (if applicable)

No response

Environment

MacOs Sonoma, Apple M2 Pro Chip.
Nativescript iOS.

Please accept these terms

@paulmlilo paulmlilo added the bug-pending-triage Reported bug, pending triage to confirm. label Apr 15, 2024
@rigor789
Copy link
Member

Can you confirm this happens even after running ns clean first?

Please also include the contents of your package.json.

@NathanWalker
Copy link
Contributor

This can also be seen if you haven't cleared DerivedData in awhile.
You can run this command:

rm -rf ~/Library/Developer/Xcode/DerivedData

Then ns clean and run.

@NathanWalker NathanWalker added needs more info and removed bug-pending-triage Reported bug, pending triage to confirm. labels Apr 15, 2024
@paulmlilo
Copy link
Author

paulmlilo commented Apr 15, 2024

@rigor789 Yes it happens after running ns clean.

Here is my package.json.

{
  "name": "app",
  "main": "./src/main.ts",
  "version": "2.1.1",
  "private": true,
  "nativescript": {
    "id": "example.example.app"
  },
  "dependencies": {
    "@angular/animations": "~17.3.4",
    "@angular/common": "~17.3.4",
    "@angular/compiler": "~17.3.4",
    "@angular/core": "~17.3.4",
    "@angular/forms": "~17.3.4",
    "@angular/platform-browser": "~17.3.4",
    "@angular/platform-browser-dynamic": "~17.3.4",
    "@angular/router": "~17.3.4",
    "@heywhy/ns-secure-storage": "~0.3.0",
    "@nativescript-community/push": "~1.1.11",
    "@nativescript-community/ui-image": "~4.3.40",
    "@nativescript-community/ui-mapbox": "~6.2.27",
    "@nativescript-community/ui-material-bottomnavigationbar": "~7.2.49",
    "@nativescript-community/ui-material-slider": "^7.2.49",
    "@nativescript-community/ui-pager": "~14.1.19",
    "@nativescript-community/ui-pulltorefresh": "~2.5.3",
    "@nativescript-community/universal-links": "^3.0.1",
    "@nativescript/angular": "~17.0.0",
    "@nativescript/appavailability": "~2.0.0",
    "@nativescript/auto-fit-text": "~1.0.3",
    "@nativescript/biometrics": "~1.3.1",
    "@nativescript/camera": "~5.1.0",
    "@nativescript/contacts": "~2.1.0",
    "@nativescript/core": "~8.7.0",
    "@nativescript/datetimepicker": "~2.1.13",
    "@nativescript/geolocation": "~8.3.1",
    "@nativescript/haptics": "^3.0.2",
    "@nativescript/imagepicker": "~3.1.1",
    "@nativescript/iqkeyboardmanager": "~2.1.1",
    "@nativescript/social-share": "~2.3.0",
    "@nativescript/tailwind": "^2.0.1",
    "@nativescript/theme": "~3.0.1",
    "@nstudio/ui-collectionview": "~5.1.8",
    "@triniwiz/nativescript-star-ratings": "^2.0.3",
    "anchorme": "^3.0.5",
    "dayjs": "^1.11.10",
    "geolocation-utils": "~1.2.5",
    "global": "^4.4.0",
    "google-libphonenumber": "~3.2.34",
    "jwt-decode": "3.1.2",
    "lodash": "^4.17.21",
    "nativescript-audio": "^6.2.6",
    "nativescript-barcodescanner": "~4.1.2",
    "nativescript-calendar": "~3.0.0",
    "nativescript-clipboard": "^2.1.1",
    "nativescript-feedback": "^2.0.0",
    "nativescript-hook": "~0.2.5",
    "nativescript-imagecropper": "~4.0.3",
    "nativescript-inappbrowser": "^3.2.0",
    "nativescript-phone": "^3.0.3",
    "nativescript-uuid-v2": "~2.0.1",
    "ngx-mask": "^17.0.7",
    "rxjs": "~7.8.1",
    "short-crypt": "^3.0.6",
    "tailwindcss": "~3.4.3",
    "throttle-debounce": "~5.0.0",
    "ts-deepmerge": "^7.0.0",
    "zone.js": "~0.14.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~17.3.4",
    "@angular/compiler-cli": "~17.3.4",
    "@nativescript/android": "~8.7.0",
    "@nativescript/debug-ios": "~1.0.0",
    "@nativescript/ios": "8.7.0",
    "@nativescript/types": "~8.7.0",
    "@nativescript/types-android": "~8.7.0",
    "@nativescript/types-ios": "~8.7.0",
    "@nativescript/webpack": "^5.0.19",
    "@ngtools/webpack": "~17.3.4",
    "@types/lodash": "~4.17.0",
    "@types/node": "~20.12.7",
    "@types/throttle-debounce": "^5.0.2",
    "postcss": "^8.4.38",
    "postcss-loader": "^8.1.1",
    "prettier": "~3.2.5",
    "prettier-plugin-organize-imports": "^3.2.4",
    "prettier-plugin-tailwindcss": "^0.5.13",
    "typescript": "~5.4.5"
  },
  "packageManager": "[email protected]"
}

@paulmlilo
Copy link
Author

@NathanWalker, I ran rm -rf ~/Library/Developer/Xcode/DerivedData and then ns clean but it still returns the same error.

@paulmlilo paulmlilo changed the title Uncaught ReferenceError: NativeScriptViewFactory is not defined Uncaught ReferenceError: NativeScriptViewFactory is not defined on iOS built with mode --release. Apr 15, 2024
@israelglory
Copy link

I am also having this exact error. Please can we get help with this ? @NathanWalker

@israelglory
Copy link

@NathanWalker @paulmlilo apparently i inspected the error to the nodemudles and figured the nativescript core ios utils folder has an index.js folder and this function is the one causing my app to break, :

export function getWindow() {
let window;
if (SDK_VERSION >= 15) {
// UIWindowScene.keyWindow is only available 15+
window = NativeScriptViewFactory.getKeyWindow(); <--------- the problem
}
if (window) {
return window;
}
const app = UIApplication.sharedApplication;
if (!app) {
return;
}
return app.keyWindow || (app.windows && app.windows.count > 0 && app.windows.objectAtIndex(0));
}

please what do you need to do ?

@pazaan
Copy link

pazaan commented Apr 19, 2024

I can repro this just using a blank sample project.

I'm on a 2019 Intel MBP running macOS 14.4.1, with Xcode 15.3, iOS SDK 17.4 and ns 8.7.0.

% ns create vue-sample --vue --ts
% cd vue-sample
% ns run ios # works fine, runs on my attached device
% ns run ios --bundle --release # runs, then crashes on my attached device

The generated package.json is:

{
  "name": "vue-sample",
  "main": "app/app.ts",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@nativescript/core": "~8.7.0",
    "@nativescript/theme": "~3.0.2",
    "nativescript-vue": "~2.9.3"
  },
  "devDependencies": {
    "@nativescript/ios": "8.7.0",
    "@nativescript/types": "~8.7.0",
    "@nativescript/webpack": "~5.0.19",
    "@types/node": "~17.0.21",
    "nativescript-vue-template-compiler": "~2.9.3",
    "typescript": "~5.4.0",
    "vue": "~2.6.12"
  }
}

Crashes with:

  ***** Fatal JavaScript exception - application has been terminated. *****
  NativeScript encountered a fatal error:
  Uncaught ReferenceError: NativeScriptViewFactory is not defined
   at
  	getWindow(file:///var/containers/Bundle/Application/367C52DC-DF32-40B1-846F-30F36C41A51B/vuesample.app/app/vendor.js:2:861673)
  	at get window(file:///var/containers/Bundle/Application/367C52DC-DF32-40B1-846F-30F36C41A51B/vuesample.app/app/vendor.js:2:27298)
  	at didFinishLaunchingWithOptions(file:///var/containers/Bundle/Application/367C52DC-DF32-40B1-846F-30F36C41A51B/vuesample.app/app/vendor.js:2:29697)
  	at (file:///var/containers/Bundle/Application/367C52DC-DF32-40B1-846F-30F36C41A51B/vuesample.app/app/vendor.js:2:23442)

I noticed that the --release version has a minified vendor.js, whereas the non-release version doesn't. I'll keep digging into this to see if I can narrow it down some more.

Webpack was a red herring. When I explicitly set mode to development, I still get the crash.

It doesn't even have to be a Vue example. I get the same even when doing a vanilla TS project: ns create example-app --ts

@pazaan
Copy link

pazaan commented Apr 19, 2024

I got back on my feet again by downgrading to @nativescript/core": "~8.6.2 and @nativescript/ios": "8.6.4.

@NathanWalker
Copy link
Contributor

I'm curious @pazaan @israelglory @paulmlilo if the projects where you're seeing this have a build.xcconfig or Podfile you could share?
We're not seeing this here, even with ns create, so perhaps something else we could check that could bring about the condition?
If each would be able to respond with output of following would be helpful as well:

node -v
npm -v
ns -v
ruby --version
pod --version

@israelglory
Copy link

israelglory commented Apr 19, 2024

v20.3.1
9.6.7
8.7.0
✔ Up to date.
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [arm64-darwin22]
1.15.2

@NathanWalker

@CatchABus
Copy link
Contributor

CatchABus commented Apr 19, 2024

v20.3.1 9.6.7 8.7.0 ✔ Up to date. ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [arm64-darwin22] 1.15.2

@NathanWalker

We happen to have a fix in next release that solves problems similar to this one: NativeScript/ios#248
Can you try npm i @nativescript/ios@next and see if next solves it for you?

@pazaan
Copy link

pazaan commented Apr 20, 2024

I'm curious @pazaan @israelglory @paulmlilo if the projects where you're seeing this have a build.xcconfig or Podfile you could share? We're not seeing this here, even with ns create, so perhaps something else we could check that could bring about the condition? If each would be able to respond with output of following would be helpful as well:

node -v
npm -v
ns -v
ruby --version
pod --version
% node -v
v20.12.2
% npm -v # Intentionally downgraded because of https://github.com/NativeScript/NativeScript/issues/10509
10.3.0
% ns -v
8.7.0
✔ Up to date.
% ruby --version
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-darwin22]
% pod --version
1.15.2

I don't have a Podfile:

% find . -name "*Podfile*"
%

@NathanWalker Which build.xcconfig would you like to see?

% find . -name build.xcconfig         
./platforms/ios/build/Release-iphoneos/exampleapp.xcarchive/Products/Applications/exampleapp.app/build.xcconfig
./platforms/ios/build/Debug-iphoneos/exampleapp.xcarchive/Products/Applications/exampleapp.app/build.xcconfig
./platforms/ios/exampleapp/build.xcconfig
./platforms/ios/exampleapp/Resources/build.xcconfig
./node_modules/@nativescript/ios/framework/__PROJECT_NAME__/build.xcconfig
./App_Resources/iOS/build.xcconfig

Edit: Assume you mean App_Resources...

ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = E53PUHPBVX

@pazaan
Copy link

pazaan commented Apr 20, 2024

We happen to have a fix in next release that solves problems similar to this one: NativeScript/ios#248
Can you try npm i @nativescript/ios@next and see if next solves it for you?

Updating to next didn't appear to help.

% npm i -D @nativescript/ios@next
% ns run ios --clean --release # <--- still crashes

@israelglory
Copy link

I got back on my feet again by downgrading to @nativescript/core": "~8.6.2 and @nativescript/ios": "8.6.4.

Worked...

@paulmlilo
Copy link
Author

@NathanWalker
Screenshot 2024-04-23 at 01 37 34

@tomcoonen
Copy link

I don't know if it's related, but I also had an issue on 8.7.0 (release build):

Fatal Exception: java.lang.RuntimeException Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function ReferenceError: __registerDomainDispatcher is not defined File: (file:///data/data/xxxx/files/app/vendor.js:2:849906) StackTrace: (file:///data/data/xxxx/files/app/vendor.js:2:849907)

@rigor789
Copy link
Member

@tomcoonen was @nativescript/android updated to 8.7.x as well? I believe the stack you shared can happen when using core 8.7.x but old android runtime version. I think we can add another check before including the inspector_modules in webpack to ensure both core and runtime are supporting them.

@tomcoonen
Copy link

@rigor789 Yes, I tried manually and also using the migrate command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants