NativeScript / NativeScript

⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Dart (Flutter) and you name it compatible.
https://nativescript.org
MIT License
23.76k stars 1.65k forks source link

ReferenceError: NSURLSessionConfiguration is not defined #10497

Closed b4rtt closed 2 months ago

b4rtt commented 2 months ago

Issue Description

After installing the project ns create example-app --ng and after updating the XCode SDK to version 17.4, the application cannot run on a real device. The app installs but after launching the app a black screen appears and after a while the app crashes. Interestingly, everything works properly in the simulator.

The app does not work even after building it for the AppStore. The app builds fine, I upload it to the Appstore and after installing it via Testflight, the black screen appears again and the app crashes after a while.

Just yesterday I had the SDK 17.2 installed in XCode and everything worked on it.

I first detected the whole problem on my production app, which I've had in the Appstore for a few years now, and now I can't release an update.

So I tried to create a completely clean project using ns create example-app --ng.

Reproduction

ns create example-app --ng

ns run ios (have connected iPhone 13 pro)

Relevant log output (if applicable)

Here is the error code that appears in the console after a while: (running ns run ios - with connected iphone 13 PRO):

Successfully run application org.nativescript.app on device with ID 00008110-00011DC922F9801EES.
  NativeScript debugger has opened inspector socket on port 18183 for org.nativescript.app.
  ***** Fatal JavaScript exception - application has been terminated. *****
  NativeScript encountered a fatal error:
  Error calling module function
  ReferenceError: NSURLSessionConfiguration is not defined
  File: (file: src/webpack:/app/webpack/bootstrap:27:0
  StackTrace:
    ./node_modules/@nativescript/core/http/http-request/index.ios.js(file: src/webpack:/app/node_modules/@nativescript/core/http/http-request/index.ios.js:15:0
    at __webpack_require__(file: src/webpack:/app/webpack/bootstrap:24:0
    at fn(file: src/webpack:/app/webpack/runtime/hot module replacement:62:0
    at ./node_modules/@nativescript/core/xhr/index.js(file:///app/vendor.js:47420:63)
    at __webpack_require__(file: src/webpack:/app/webpack/bootstrap:24:0
    at fn(file: src/webpack:/app/webpack/runtime/hot module replacement:62:0
    at (file: src/webpack:/app/node_modules/@nativescript/core/globals/index.js:263:43
    at loadModule(file: src/webpack:/app/node_modules/@nativescript/core/globals/index.js:202:0
    at get(file: src/webpack:/app/node_modules/@nativescript/core/globals/index.js:8:0
    at (file: src/webpack:/app/node_modules/@nativescript/core/fetch/index.js:12:0
    at (file: src/webpack:/app/node_modules/@nativescript/core/fetch/index.js:17:13
    at ./node_modules/@nativescript/core/fetch/index.js(file: src/webpack:/app/node_modules/@nativescript/core/fetch/index.js:539:1
    at __webpack_require__(file: src/webpack:/app/webpack/bootstrap:24:0
    at fn(file: src/webpack:/app/webpack/runtime/hot module replacement:62:0
    at (file: src/webpack:/app/node_modules/@nativescript/core/globals/index.js:265:45
    at loadModule(file: src/webpack:/app/node_modules/@nativescript/core/globals/index.js:202:0
    at get(file:///app/ve<\M-b\M^@\M-&>
Successfully synced application org.nativescript.app on device 00008110-00011DC922F9801E.

### Environment

```yaml
OS: macOS 14.3.1
CPU: (8) arm64 Apple M1
Shell: /bin/zsh
node: 20.9.0
npm: 10.1.0
nativescript: 8.6.5

# android
java: 18.0.1.1
ndk: Not Found
apis: Not Found
build_tools: Not Found
system_images: Not Found

# ios
xcode: 15.3/15E204a
cocoapods: 1.14.3
python: 2.7.18
python3: 3.10.5
ruby: 2.6.10
platforms:
  - DriverKit 23.4
  - iOS 17.4
  - macOS 14.4
  - tvOS 17.4
  - visionOS 1.1
  - watchOS 10.4

Dependencies

"dependencies": {
  "@angular/animations": "~16.2.0",
  "@angular/common": "~16.2.0",
  "@angular/compiler": "~16.2.0",
  "@angular/core": "~16.2.0",
  "@angular/forms": "~16.2.0",
  "@angular/platform-browser": "~16.2.0",
  "@angular/platform-browser-dynamic": "~16.2.0",
  "@angular/router": "~16.2.0",
  "@nativescript/angular": "^16.0.0",
  "@nativescript/core": "~8.6.0",
  "@nativescript/theme": "~3.0.2",
  "rxjs": "~7.8.0",
  "zone.js": "~0.13.0"
},
"devDependencies": {
  "@angular-devkit/build-angular": "~16.2.0",
  "@angular/compiler-cli": "~16.2.0",
  "@nativescript/types": "~8.6.0",
  "@nativescript/webpack": "~5.0.18",
  "@ngtools/webpack": "~16.2.0",
  "typescript": "~5.1.6"
}

Please accept these terms

milleniumfrog commented 2 months ago

I had the same issue. Downgrading XCode to version 15.2 fixed this issue. You can download older versions of XCode here: https://developer.apple.com/xcode/resources/

gabrielbiga commented 2 months ago

Hello all! I'm having the same issue right now as well. Here I describe all the steps, example app and versions too. https://github.com/NativeScript/ios/issues/241 I think this issue is top 1 priority, as it totally blocks all NS ecosystem on iOS.

rigor789 commented 2 months ago

Does this happen with the 8.6.4-next.2024-02-21-7992943232 runtime?

gabrielbiga commented 2 months ago

Update: I just built the app with Xcode 15.2 following the @milleniumfrog 's hint and it did work at my iPhone 12 iOS 17.4. The app is running well, so lets see if it works at AppStore review, I keep you posted. Now I'm going to update Xcode again and test the release that you said @rigor789.

gabrielbiga commented 2 months ago

@rigor789 I just tested this new runtime: 8.6.4-next.2024-02-21-7992943232` and it did not work. The error persists under Xcode 15.3.0 even updating the runtime. Looks like the native bridge is crazy, some objc classes are not accessible anymore and it is very random, lots of classes still work but someones are totally unaccessible.

rigor789 commented 2 months ago

Thank you @gabrielbiga for testing it out - looks like sticking with Xcode 15.2 is the way to go for now.

For anyone running into this, highly recommend Xcodes App to manage Xcode versions: https://github.com/XcodesOrg/XcodesApp

(Or if you use AppStore, disable automatic updates).

We'll be looking further into this, but in the meantime the above should get you going.

edusperoni commented 2 months ago

this PR should fix it (hopefully) https://github.com/NativeScript/ios/pull/242

Apparently the iPhone SDK 17.4 can't detect that it's an iPhone anymore, so some variables seem to be missing. We should release a new version soon with this fix, but in the meantime you can test it out yourself and give some feedback to see if it works:

  1. download the "npm_release" build artifact from here https://github.com/NativeScript/ios/actions/runs/8210029428
  2. unzip it through the command line (unzip npm_release.zip). If you unzip through finder it'll unzip twice...
  3. npm i -D path/to/extracted/nativescript-ios-8.6.4-pr.242-2024-03-08-8210029428
  4. rm -rf platforms
  5. try running the app again and please report back if there are any other issues
NathanWalker commented 2 months ago

Fixed on @nativescript/ios “next”, which you can use right now, and will be part of 8.7 this week.

ray007 commented 2 months ago

Any idea when this will be in the standard release?

triniwiz commented 2 months ago

@ray007 try out 8.6.4

ray007 commented 2 months ago

Seems to work, thank you. Guess I forgot the ns clean yesterday...

ThiagoAllves commented 2 months ago

@triniwiz is right, this PR https://github.com/NativeScript/ios/pull/242 solves the compilation problem that is happening with XCode 15.3+, you don't need to downgrade the version, just change the version of "@nativescript/ios" to "8.6.4",