NathanaelA / nativescript-websockets

Websockets for NativeScript
83 stars 43 forks source link

[iOS/NS8/NG11] Module parse failed: 'return' outside of function #105

Closed phenric closed 2 years ago

phenric commented 2 years ago

Hi all, Thank you @NathanaelA for all the modules you did.

While using this module with NS 8.2.3 and NG 11 on the iOS simulator (Apple M1), I'm facing some issues during the require.

The first one, is concerning the return in the package:

 ERROR in ../node_modules/@master.technology/websockets/websockets-base.js 21:4
 Module parse failed: 'return' outside of function (21:4)
 You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
 | if (parseFloat(UIDevice.currentDevice.systemVersion) < 13.0) {
 |     module.exports = require("./websockets-pocketsocket");
 >     return;
 | }
 | 
  @ ../node_modules/@master.technology/websockets/websockets.js 11:25-53

As a test I commented the returns and here is the second issue:

ERROR in ../node_modules/@master.technology/websockets/websockets-base.js 37:47
Module parse failed: Unexpected token (37:47)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|             console.log("WebSocket Event: URLSessionWebSocketTaskDidOpenWithProtocol");
|         }
>         const webSocketInstance = this.wrapper?.get?.();
|         if (!webSocketInstance) {
|             return;
 @ ../node_modules/@master.technology/websockets/websockets.js 11:25-53

Do you face the same issue? Do you heard someone facing the same? Let me know if you could help me or if you're facing the same. Thx

phenric commented 2 years ago

Could it be due to my webpack version?

  "dependencies": {
    "@angular/animations": "~11.0.0",
    "@angular/common": "~11.0.0",
    "@angular/compiler": "~11.0.0",
    "@angular/core": "~11.0.0",
    "@angular/forms": "~11.0.0",
    "@angular/platform-browser": "~11.0.0",
    "@angular/platform-browser-dynamic": "~11.0.0",
    "@angular/router": "~11.0.0",
    "@master.technology/websockets": "file:../src",
    "@nativescript/angular": "~11.0.0",
    "@nativescript/core": "~7.1.0",
    "@nativescript/firebase": "^11.1.3",
    "@nativescript/localize": "^5.0.4",
    "@nativescript/theme": "~3.0.1",
    "@sergeymell/nativescript-svg": "^1.1.0",
    "@triniwiz/nativescript-image-cache-it": "^7.0.9",
    "copy-webpack-plugin": "^6.0.4",
    "nativescript-phone": "^3.0.3",
    "nativescript-sqlite": "^2.7.0",
    "nativescript-toasty": "^3.0.0-alpha.2",
    "nativescript-ui-sidedrawer": "~9.0.0",
    "reflect-metadata": "~0.1.12",
    "rxjs": "^6.6.0",
    "sass": "^1.52.2",
    "zone.js": "~0.11.1"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~11.0.0",
    "@nativescript/android": "8.1.1",
    "@nativescript/ios": "8.2.2",
    "@nativescript/webpack": "^4.1.0",
    "@ngtools/webpack": "~11.0.0",
    "codelyzer": "~6.0.0",
    "node-sass": "^4.14.1",
    "tslint": "~6.1.3",
    "typescript": "~4.0.0"
  }
phenric commented 2 years ago

Ok guys, I fix this issue. The problem was my webpack version as I suspected it.

I upgraded the webpack version to 5 and ran npx nativescript-webpack init. Now the app starts and I've to configure the webpack ;)