Error with importing from SystemJS #953

Open
opened 2018-01-03 14:09:46 +00:00 by zdimon · 3 comments
zdimon commented 2018-01-03 14:09:46 +00:00 (Migrated from github.com)

Hello.
When I tried to use this plugin I got such error.

Error: Unexpected value 'undefined' imported by the module 'AppModule'

And to eliminate this, I had to put that line in the index.js.

Object.defineProperty(exports, "__esModule", { value: true });

Because I got undefined value after importing in NgModule.

I don`t know is it a bug or I did something wrong?

Hello. When I tried to use this plugin I got such error. > Error: Unexpected value 'undefined' imported by the module 'AppModule' And to eliminate this, I had to put that line in the index.js. > Object.defineProperty(exports, "__esModule", { value: true }); Because I got undefined value after importing in NgModule. I don`t know is it a bug or I did something wrong?
MinaMagdyBoshra commented 2018-01-16 17:57:59 +00:00 (Migrated from github.com)

can share code ??

can share code ??
xileftenurb commented 2018-05-18 19:31:32 +00:00 (Migrated from github.com)

I found a way to make it working like so :
in app.module.ts

import * as FileUploadModuleObj from 'ng2-file-upload'; const FileUploadModule = (FileUploadModuleObj as any).default.FileUploadModule;

I then can import FileUploadModule in my NgModule.

I use (FileUploadModuleObj as any) because vscode wrongly think FileUploadModuleObj do not have an default value (and have a bunch of other value he do not really have)

with this, I did not need to modify the code of the module.

the downside is that it broke all intellisense when using any part of the module, because every part must be find inder the "defaults" attribute

I found a way to make it working like so : in `app.module.ts` `` import * as FileUploadModuleObj from 'ng2-file-upload'; const FileUploadModule = (FileUploadModuleObj as any).default.FileUploadModule; `` I then can import FileUploadModule in my NgModule. I use `(FileUploadModuleObj as any)` because vscode wrongly think FileUploadModuleObj do not have an default value (and have a bunch of other value he do not really have) with this, I did not need to modify the code of the module. the downside is that it broke all intellisense when using any part of the module, because every part must be find inder the "defaults" attribute
xileftenurb commented 2018-05-18 20:00:01 +00:00 (Migrated from github.com)

I finally successfully implemented the solution of zdimon :
index.js

"use strict";
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}

Object.defineProperty(exports, "__esModule", { value: true }); //added this line!!

__export(require("./file-upload/file-select.directive"));
__export(require("./file-upload/file-drop.directive"));
__export(require("./file-upload/file-uploader.class"));
__export(require("./file-upload/file-item.class"));
__export(require("./file-upload/file-like-object.class"));
var file_upload_module_1 = require("./file-upload/file-upload.module");
exports.FileUploadModule = file_upload_module_1.FileUploadModule;

systemjs.config.js

map : {
    ...
    'ng2-file-upload'   : node_modules/ng2-file-upload'
    ...
},
meta : {
     'ng2-file-upload/*' : {
          format : 'cjs'
     }
},
packages : {
      'ng2-file-upload' : {
           defaultExtension : 'js',
           main : 'index.js'
      }
}

not sure if everything is 100% correct, but it work.

I finally successfully implemented the solution of zdimon : index.js ``` "use strict"; function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); //added this line!! __export(require("./file-upload/file-select.directive")); __export(require("./file-upload/file-drop.directive")); __export(require("./file-upload/file-uploader.class")); __export(require("./file-upload/file-item.class")); __export(require("./file-upload/file-like-object.class")); var file_upload_module_1 = require("./file-upload/file-upload.module"); exports.FileUploadModule = file_upload_module_1.FileUploadModule; ``` systemjs.config.js ``` map : { ... 'ng2-file-upload' : node_modules/ng2-file-upload' ... }, meta : { 'ng2-file-upload/*' : { format : 'cjs' } }, packages : { 'ng2-file-upload' : { defaultExtension : 'js', main : 'index.js' } } ``` not sure if everything is 100% correct, but it work.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#953