Uncaught ReferenceError: exports is not defined and require

后端 未结 3 1992
一向
一向 2021-01-12 03:36

I\'m using angularjs and typescript to create some app, I\'m having a trouble with this error that I can\'t solve

Here is my *.ts code

export var NgA         


        
相关标签:
3条回答
  • 2021-01-12 03:58

    click here "Solved finally" 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.

    {
        "compilerOptions": {
        "target": "es5",
        "module": "es6",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": [ "es2015", "dom" ],
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true
        }
    
    }
    
    0 讨论(0)
  • 2021-01-12 04:03

    How can I use import like es6 in typescript? What I am missing?

    You need to use a module loader. Here is a sample that uses webpack : https://github.com/AngularClass/angular2-webpack-starter

    0 讨论(0)
  • 2021-01-12 04:05

    I use angular 1.6 and webpack, it works on my side when i changed the module to "umd"

    UMD: Universal Module Definition This has brought about the push for a “universal” pattern that supports both styles (AMD and CommonJS)

    reference: http://davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/

    pasted here is my tsconfig.json after I changed it, I run $ tsc

    {
      "compilerOptions": {
        "target": "es5",
        "module": "umd",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": [ "es2015", "dom" ],
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "allowUnreachableCode": true
      },
      "exclude": [
        "node_modules"
      ]
    }
    

    then my "exports is not defined" error is gone.

    0 讨论(0)
提交回复
热议问题