Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: exports is not defined #575

Closed
Rui90 opened this issue Feb 8, 2017 · 19 comments
Closed

Uncaught ReferenceError: exports is not defined #575

Rui90 opened this issue Feb 8, 2017 · 19 comments

Comments

@Rui90
Copy link

Rui90 commented Feb 8, 2017

In the Swagger Code Generation there is a few exports that are being added to the code on compile. Like this one for instance:

exports.AuthClient = AuthClient;

I have no idea what this exports is doing, I just know that I am having a problem with it:

Uncaught ReferenceError: exports is not defined

Anyone could explain me what is the exports for and why am I getting that error and how to fix/avoid it?

@RicoSuter
Copy link
Owner

I think in your tsconfig.json you have selected the wrong module system... i think this is a TypeScript issue and not an NSwag issue

@Rui90
Copy link
Author

Rui90 commented Feb 8, 2017

@RSuter yes I believe you must be right... Could you help me chose the best approach for building the interface? Maybe this one?

http://imgur.com/63bda89f-e7a0-44cf-b377-6e1383e4e528

@RicoSuter
Copy link
Owner

The link is not working... The problem is that the tooling is not correctly working in your JS project

@Rui90
Copy link
Author

Rui90 commented Feb 8, 2017

@RicoSuter
Copy link
Owner

I always use class in my project, because it converts to properties to lower case (JS-style) and also correctly converts date objects correctly. But you cannot use duck-typing - you need to pass instances of the expected classes.

And yes, you can choose "Interface" as Type Style, this way you just have to provide an object which satisfies the interface...

@Rui90
Copy link
Author

Rui90 commented Feb 8, 2017

but the problem with exports remains

@RicoSuter
Copy link
Owner

Yes, this is a problem with your TypeScript compiler settings in your project... I think it is configured to compile to AMD modules but your module loader cannot use this

@Rui90
Copy link
Author

Rui90 commented Feb 8, 2017

what can I do then? I'm kinda newbie with this, I have no idea

@Rui90
Copy link
Author

Rui90 commented Feb 9, 2017

swagger specification:

{
  "swaggerGenerator": {
    "webApiToSwagger": {
      "assemblyPaths": [
        "AppBackend/AppBackend/bin/AppBackend.dll"
      ],
      "referencePaths": [],
      "isAspNetCore": false,
      "controllerNames": [
        "AppBackend.Controllers.AuthController",
        "AppBackend.Controllers.LessorController",
        "AppBackend.Controllers.UserController"
      ],
      "defaultUrlTemplate": "api/{controller}/{id}",
      "defaultPropertyNameHandling": "Default",
      "defaultEnumHandling": "Integer",
      "flattenInheritanceHierarchy": false,
      "generateKnownTypes": true,
      "generateXmlObjects": false,
      "addMissingPathParameters": false,
      "infoTitle": "Web API Swagger specification",
      "infoVersion": "1.0.0",
      "output": null
    }
  },
  "codeGenerators": {
    "swaggerToTypeScriptClient": {
      "className": "{controller}Client",
      "moduleName": "",
      "namespace": "",
      "typeScriptVersion": 1.8,
      "template": "AngularJS",
      "promiseType": "Promise",
      "dateTimeType": "Date",
      "generateClientClasses": true,
      "generateClientInterfaces": true,
      "wrapDtoExceptions": false,
      "useTransformOptionsMethod": false,
      "useTransformResultMethod": false,
      "generateDtoTypes": true,
      "operationGenerationMode": "MultipleClientsFromOperationId",
      "markOptionalProperties": true,
      "typeStyle": "Interface",
      "generateDefaultValues": true,
      "excludedTypeNames": [],
      "output": "RenterLogApiBackendClient.ts"
    },
    "swaggerToCSharpClient": {
      "exceptionClass": "SwaggerException",
      "generateClientClasses": true,
      "generateClientInterfaces": false,
      "generateDtoTypes": true,
      "injectHttpClient": false,
      "wrapSuccessResponses": false,
      "useHttpClientCreationMethod": false,
      "useHttpRequestMessageCreationMethod": false,
      "generateExceptionClasses": true,
      "generateContractsOutput": false,
      "className": "{controller}Client",
      "namespace": "MyNamespace",
      "requiredPropertiesMustBeDefined": true,
      "dateType": "System.DateTime",
      "dateTimeType": "System.DateTime",
      "timeType": "System.TimeSpan",
      "timeSpanType": "System.TimeSpan",
      "arrayType": "System.Collections.ObjectModel.ObservableCollection",
      "dictionaryType": "System.Collections.Generic.Dictionary",
      "classStyle": "Inpc",
      "operationGenerationMode": "MultipleClientsFromOperationId",
      "generateDefaultValues": true,
      "excludedTypeNames": [],
      "output": null
    },
    "swaggerToCSharpController": {
      "className": "{controller}",
      "namespace": "MyNamespace",
      "additionalNamespaceUsages": [
        "System.Web.Http"
      ],
      "requiredPropertiesMustBeDefined": true,
      "dateType": "System.DateTime",
      "dateTimeType": "System.DateTime",
      "timeType": "System.TimeSpan",
      "timeSpanType": "System.TimeSpan",
      "arrayType": "System.Collections.Generic.IEnumerable",
      "dictionaryType": "System.Collections.Generic.Dictionary",
      "classStyle": "Inpc",
      "operationGenerationMode": "MultipleClientsFromOperationId",
      "generateDefaultValues": true,
      "excludedTypeNames": [],
      "output": null
    }
  }
}

@Rui90
Copy link
Author

Rui90 commented Feb 9, 2017

is there anyway to typescript does not generate the exports?

@RicoSuter
Copy link
Owner

What module loader are you using in your AngJS project?

@Rui90
Copy link
Author

Rui90 commented Feb 10, 2017

@RSuter I don't think I am using any, but If I am, probably is Angular DI.

@RicoSuter
Copy link
Owner

Then myabe you have to define None in the module parameter:

https://www.typescriptlang.org/docs/handbook/compiler-options.html

@Rui90
Copy link
Author

Rui90 commented Feb 13, 2017

@RSuter think that is the problem... unfortunately can't compile with none :/

tsc typescriptclient.ts --module None
typescriptclient.ts(9,18): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.

@Rui90
Copy link
Author

Rui90 commented Feb 21, 2017

Any more suggestions?

@RicoSuter
Copy link
Owner

Maybe try:

https://www.npmjs.com/package/typescript-bundle

this generates a JS bundle which you can directly import and use without a module loader...

@umeshshende
Copy link

microsoft/TypeScript#6319 "Solved finally" follow this ..i was also getting same error i changed module:"commonjs" to "module": "es6", because targeting ES5 remove the import/export statements, so these tools cannot remove unused exports.

@Rui90
Copy link
Author

Rui90 commented Mar 14, 2017

@umesh190690 where do I change that? In compilation?

tsc typescriptclient.ts --module es6 ?

I compiled that way and I got ApiBackendClient.js:555 Uncaught SyntaxError: Unexpected token export beucase it still has an export :(

@RicoSuter
Copy link
Owner

Closed because this is a TS tooling issue and not an nswag issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants