NativeScript / nativescript-dev-webpack

A package to help with webpacking NativeScript apps.
Apache License 2.0
97 stars 49 forks source link

Webpack do not work for "this.constructor = d;" #16

Closed ignaciolarranaga closed 8 years ago

ignaciolarranaga commented 8 years ago

For example it does not work for the geolocation module, because of this code (extracted from the bundled code):

!*** ../~/nativescript-geolocation/nativescript-geolocation.ios.js ***!
  \*********************************************************************/
/***/ function(module, exports, __webpack_require__) {

    "use strict";
    var __extends = (this && this.__extends) || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };

At runtime it throws:

Sep  4 18:04:19 MacBook-Pro-de-Ignacio xxxx[51653]: 1   0x108ff4c67 -[TNSRuntime executeModule:]
Sep  4 18:04:19 MacBook-Pro-de-Ignacio xxxx[51653]: 2   0x106194322 main
Sep  4 18:04:19 MacBook-Pro-de-Ignacio xxxx[51653]: 3   0x10bb6e92d start
Sep  4 18:04:19 MacBook-Pro-de-Ignacio xxxx[51653]: 4   0x1
Sep  4 18:04:19 MacBook-Pro-de-Ignacio xxxx[51653]: file:///app/bundle.js:145226:26: JS ERROR TypeError: Attempted to assign to readonly property.
Sep  4 18:04:19 MacBook-Pro-de-Ignacio com.apple.CoreSimulator.SimDevice.00A4117D-42D7-4D34-A741-4D4FAA4286CD.launchd_sim[96565] (UIKitApplication:com.gynto.client[0x5ed0][51653]): Service exited due to signal: Segmentation fault: 11

This is just an example, but also happen to me on other modules. The only pattern I was able to found is that happends at: function __() { this.constructor = d; }

hdeshev commented 8 years ago

I think the iOS runtime has issues with code using the "use strict" declaration. I think nativescript-geolocation has to be compiled without that.

hdeshev commented 8 years ago

This issue was moved to NativeScript/nativescript-geolocation#32

ignaciolarranaga commented 8 years ago

I don't think it is a problem of geolocation, the "use strict" appears 463 times in my bundle :)

Check for example this piece, it is the app component:

/*!************************!*\
  !*** ./app.context.js ***!
  \************************/
/***/ function(module, exports, __webpack_require__) {

    "use strict";
    var core_1 = __webpack_require__(/*! @angular/core */ 146);
    /**
     * This class represents a particular context (a company selected, a product, selected, etc.)
     */
    var AppContext = (function () {
        function AppContext() {
        }
        AppContext = __decorate([
            core_1.Injectable(), 
            __metadata('design:paramtypes', [])
        ], AppContext);
        return AppContext;
    }());
    exports.AppContext = AppContext;
    //# sourceMappingURL=app.context.js.map

/***/ },

This will also create an issue if the problem where the "use strict"

ignaciolarranaga commented 8 years ago

Tried:

In both cases the reason was not the mentioned here, but is there some sample project that I can try ?

hdeshev commented 8 years ago

I don't think it is a problem of geolocation, the "use strict" appears 463 times in my bundle :)

I just tried it, and removing "use strict" from the nativescript-geolocation plugin (upgrading to 0.0.13) fixed it. You can try it in this demo project -- it webpacks and works fine on my end.

ignaciolarranaga commented 8 years ago

Just to comment @hdeshev, @PeterStaev found another solution removing the helpers: https://github.com/PeterStaev/nativescript-purchase/commit/15dcc2855117a7af75177acd40993c26783076e1

hdeshev commented 8 years ago

I saw the related discussion in PeterStaev/nativescript-purchase#4, and I remember having to remove both the decorator helpers and the "use strict" option. Thanks for verifying this!

hdeshev commented 8 years ago

Oh, and one thing I forgot. I'll update the docs article with a section for library maintainers.

bnussey commented 7 years ago

Hey @hdeshev Im getting the same error but from code within my project. The error is: file:///app/bundle.js:22761:25: JS ERROR TypeError: Attempted to assign to readonly property. When looking at the bundle.js I can see:

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_file_system__ = __webpack_require__(/*! file-system */ 45);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_file_system___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_file_system__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_platform__ = __webpack_require__(/*! platform */ 10);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_platform___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_platform__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__shared_utils_using_simulator_util__ = __webpack_require__(/*! ../shared/utils/using-simulator.util */ 716);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__shared_utils_os_version_util__ = __webpack_require__(/*! ../shared/utils/os-version.util */ 715);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_timer__ = __webpack_require__(/*! timer */ 176);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_timer___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_timer__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SpotAssetManager; });
/* unused harmony export SpotAssetContainer */
/* unused harmony export SpotAssetDownloadTask */
/* unused harmony export AVAssetDownloadDelegateImpl */
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};

Any ideas on how to resolve this?

bnussey commented 7 years ago

I've also added "noImplicitUseStrict": true, on my tsconfig.json but no change

rsaf commented 7 years ago

I'm having the same error. Any solution for this? @bnussey How do you locate the file:///app/bundle.js file?

file:///app/bundle.js:45685:25: JS ERROR TypeError: Attempted to assign to readonly property. Oct 12 09:02:15 Samos-MacBook-Pro com.apple.CoreSimulator.SimDevice.1CC4E8E8-9771-4947-B5C1-0ED7CA28D7F9.launchd_sim[20909] (UIKitApplication:mobi.tamtam.TamTam[0x1c62][20931][21843]): Service exited due to Segmentation fault: 11

bnussey commented 7 years ago

Hey @rsaf that is in platforms -> ios -> appname -> bundle.js

Not sure about this issue, I think it was cause I didn't configure my tsconfig.aot.ts to have the "noImplicitUseStrict": true

rsaf commented 7 years ago

@bnussey Thank you very much for the quick response. After inspecting my bundle.js, I realized that the error was related to the nativescript-imagecropper module (version: 0.0.7). When I comment out all imagecroppring code in my app, and delete the platform folder, the error goes away.

Unfortunately setting noImplicitUseStrict": true , in the tsconfig.aot.ts didn't help.

bnussey commented 7 years ago

Hey @rsaf here is my tsconfig.aot.json for you:

{
  "extends": "./tsconfig",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "application": ["node_modules/tns-core-modules/application"],
      "application-settings": ["node_modules/tns-core-modules/application-settings"],
      "camera": ["node_modules/tns-core-modules/camera"],
      "color": ["node_modules/tns-core-modules/color"],
      "connectivity": ["node_modules/tns-core-modules/connectivity"],
      "console": ["node_modules/tns-core-modules/console"],
      "data/*": ["node_modules/tns-core-modules/data/*"],
      "fetch": ["node_modules/tns-core-modules/fetch"],
      "file-system": ["node_modules/tns-core-modules/file-system"],
      "fps-meter": ["node_modules/tns-core-modules/fps-meter"],
      "globals": ["node_modules/tns-core-modules/globals"],
      "http": ["node_modules/tns-core-modules/http"],
      "image-asset": ["node_modules/tns-core-modules/image-asset"],
      "image-source": ["node_modules/tns-core-modules/image-source"],
      "location": ["node_modules/tns-core-modules/location"],
      "platform": ["node_modules/tns-core-modules/platform"],
      "text": ["node_modules/tns-core-modules/text"],
      "timer": ["node_modules/tns-core-modules/timer"],
      "trace": ["node_modules/tns-core-modules/trace"],
      "ui/*": ["node_modules/tns-core-modules/ui/*"],
      "utils/*": ["node_modules/tns-core-modules/utils/*"],
      "xhr": ["node_modules/tns-core-modules/xhr"],
      "xml": ["node_modules/tns-core-modules/xml"]
    },
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules",
    "platforms"
  ],
  "angularCompilerOptions": {
    "skipMetadataEmit": true,
    "genDir": "./"
  }
}
rsaf commented 7 years ago

@bnussey Thanks, I actually have the same tsconfig.aot.json already.

I temporarily solved my issue by manually commenting out "use strict" in the "nativescript-imagecropper" node module as stated here: https://github.com/bthurlow/nativescript-imagecropper/issues/15

bnussey commented 7 years ago

nice you could submit PR for that plugin @rsaf