capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

bug: iOS 14.5 apps not loading global Ionic Styles in emulator

Open mrussmup opened this issue 5 years ago • 35 comments

Bug Report

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 3.0.2
  @capacitor/core: 3.0.2
  @capacitor/android: 3.0.2
  @capacitor/ios: 3.0.2

Installed Dependencies:

  @capacitor/android: not installed
  @capacitor/cli: 3.0.2
  @capacitor/ios: 3.0.2
  @capacitor/core: 3.0.2

Platform(s)

iOS 14.5

Current Behavior

App is not loading Ionic Styles. Inspecting with Safari I can see the styles.css file is empty. EDIT: Inspecting from Safari in Simulator I get this error: Did not parse stylesheet at 'capacitor://localhost/styles.css' because non CSS MIME types are not allowed in strict mode.

Expected Behavior

App styling correctly

Code Reproduction

Clone the repo: https://github.com/mrussmup/stylesbugios145

run ionic capacitor build ios Run the app in a iOS 14.5 Simulator

Other Technical Details

npm --version output: 6.14.10 node --version output: 14.15.4 pod --version output (iOS issues only): 1.10.1

Additional Context

Developing on a Mac Air M1. Opening XCode with Rosetta

mrussmup avatar Jun 29 '21 10:06 mrussmup

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

Ionitron avatar Jun 29 '21 10:06 Ionitron

Bug Report

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 3.0.2
  @capacitor/core: 3.0.2
  @capacitor/android: 3.0.2
  @capacitor/ios: 3.0.2

Installed Dependencies:

  @capacitor/android: not installed
  @capacitor/cli: 3.0.2
  @capacitor/ios: 3.0.2
  @capacitor/core: 3.0.2

Platform(s)

iOS 14.5

Current Behavior

App is not loading Ionic Styles. Inspecting with Safari I can see the styles.css file is empty. EDIT: Inspecting from Safari in Simulator I get this error: Did not parse stylesheet at 'capacitor://localhost/styles.css' because non CSS MIME types are not allowed in strict mode.

Expected Behavior

App styling correctly

Code Reproduction

Clone the repo: https://github.com/mrussmup/stylesbugios145

run ionic capacitor build ios Run the app in a iOS 14.5 Simulator

Other Technical Details

npm --version output: 6.14.10 node --version output: 14.15.4 pod --version output (iOS issues only): 1.10.1

Additional Context

Developing on a Mac Air M1. Opening XCode with Rosetta

mrussmup avatar Jul 02 '21 15:07 mrussmup

I can't reproduce, but I don't have M1 mac, it's probably related to that.

Does your www/styles.css have content? or is it empty too? And the ios/App/App/public/styles.css?

Did you see any problems on the terminal when you ran npx cap add ios or npx cap update ios or npx cap sync ios?

jcesarmobile avatar Jul 02 '21 17:07 jcesarmobile

Both files have content. The only problem is that on Safari Inspector the brwoser expects a mime type text/css but the Ionic app serves that file as octet/stream.

I haven't found any problems with all of that commands.

mrussmup avatar Jul 03 '21 11:07 mrussmup

UPDATE

No problems for me too on an older Intel Macbook Air.

mrussmup avatar Jul 04 '21 10:07 mrussmup

On M1 emulators UTTypeCreatePreferredIdentifierForTag always returns nil. https://github.com/ionic-team/capacitor/blob/b893a57aaaf3a16e13db9c33037a12f1a5ac92e0/ios/Capacitor/Capacitor/WebViewAssetHandler.swift#L64 image

Same problem with cordova-plugin-ionic-webview in Objective-C. A workaround is to explicit mapping file extension to mime. https://github.com/qrdp/cordova-plugin-ionic-webview/commit/0c2e2731a6fa655a03ebb13492acb6990af0da7d#diff-af7cc7d07bec4a8ea0e271d11092d77a789646fdfd5ce2cbdf6307b4d8198b5aR74

kppv avatar Jul 26 '21 17:07 kppv

@qrdp Still not working after installing your fork. How can I fix?

mrussmup avatar Jul 28 '21 14:07 mrussmup

@mrussmup My fork of cordova-plugin-ionic-webview is just an example (for cordova project).

I think you can try to fork Capacitor and do something like this https://github.com/qrdp/capacitor/commit/228d591b9bdc13a9513e4d7b986855e8dcb5d845

Unfortunately, I can not run the code and check it now

kppv avatar Jul 28 '21 15:07 kppv

@qrdp I'm running a Cordova project. So I have to map in that long variable of types the correct type that the app receives? Sorry about those questions but I'm absolutely not familiar with Objective-C.

mrussmup avatar Jul 29 '21 08:07 mrussmup

@mrussmup Check out the demo project https://github.com/qrdp/corodova-m-1-demo. It works fine on my MacBook M1.

https://github.com/qrdp/corodova-m-1-demo/blob/20153e4da693ed3350460361e9c6a52d2b05c70f/package.json#L54

After changing the version, it is better to clear the platform and plugin directories and rebuild project.

kppv avatar Jul 30 '21 15:07 kppv

Now is working fine. Thank you

mrussmup avatar Jul 30 '21 15:07 mrussmup

I am having same issue. On Mac with M1 because some of the frameworks don't support M1, I had to switch XCode to Rosetta. When I am doing that, project is missing all css when built.
It works fine in non Rosetta mode. I have cleared all project build folders etc. no joy

gbkwiatt avatar Aug 04 '21 08:08 gbkwiatt

I've encountered this issue days ago and turning off the "Open using Rosetta" solved my issue wherein the simulator does not render properly my app and the Safari console shows error like this: image

I turned it off by going to Finder > Right click "Xcode.app" > Get Info > Untick "Open using Rosetta" image

Additional Context

Developing on a MacBook Air M1 with macOS Big Sur 11.2.3. Opening XCode with Rosetta

Other Technical Details

npm --version: 6.14.12 node --version: 14.16.1 pod --version: 1.11.0

staizen-charles avatar Sep 10 '21 03:09 staizen-charles

closing as know apple bug, if you face the issue, use the workaround described on the last message

jcesarmobile avatar Sep 10 '21 11:09 jcesarmobile

Rosetta was already off for me (M1 Max, XCode 13). Switching on/off Rosetta had no effect. I was able to workaround by modifying my index.html to include this instead of the main.css reference. A bit wonky - I'd rather capacitor serve up with correct MIME type, but am not ready to upgrade the app, so maybe this is acceptable workaround.

  <script>
     var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
          if (this.readyState == 4 && this.status == 200) {
            document.head.innerHTML = document.head.innerHTML + '<style type="text/css">' + this.responseText; + '</style>';           
          }
      };
      xhttp.open("GET", "build/main.css", true);
      xhttp.send();
  </script>

danroot avatar Dec 02 '21 23:12 danroot

Still having the issue, turning off the "Open using Rosetta" didn't fixed it for me.

antinomy-studio avatar Feb 22 '22 08:02 antinomy-studio

I am facing the same issue. Did not parse stylesheet at 'capacitor://localhost/static/css/4.b11a87a6.chunk.css' because non CSS MIME types are not allowed in strict mode.

node - 12.14.1 @capacitor/cli - 3.2.5 @capacitor/core - 3.2.5 @capacitor/ios - 3.3.4 Screenshot 2022-03-04 at 4 31 22 PM

dheerajkhokhar avatar Mar 04 '22 11:03 dheerajkhokhar

The workaround does not work for me as well. Not using Rosetta, still getting: [Error] Did not parse stylesheet at 'capacitor://localhost/css/chunk-vendors.c95d1953.css' because non CSS MIME types are not allowed in strict mode. [Error] Did not parse stylesheet at 'capacitor://localhost/css/app.d6baf572.css' because non CSS MIME types are not allowed in strict mode.

eppleton avatar Mar 17 '22 11:03 eppleton

I'm getting the same error when I try to run an app using yarn capacitor run ios but the app loads fine when I open the project in Xcode and run it from there.

Andorbal avatar Mar 17 '22 23:03 Andorbal

Same issue when I run ionic cap run ios. When I run ionic cap build ios and run it through xcode it works fine.

raminnoodle avatar Mar 18 '22 22:03 raminnoodle