Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: Can't find variable: exports

Question:

Why am I getting the following error? Did I forget to include a script in my html?

ReferenceError: Can't find variable: exports

Generated javascript from typescript that causes it:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* more code */

Extra:

tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "noImplicitAny": true,
    "rootDir": ".",
    "sourceRoot": "../../../",
    "outDir": "../../../js/dist/",
    "sourceMap": false
  },
  "exclude": [
    "node_modules"
  ]
}

requirejs is included before my js files in html

There are similar questions but this is simply about typescript and not about ember/babel/etc.

like image 255
kemicofa ghost Avatar asked Apr 07 '17 12:04

kemicofa ghost


1 Answers

I can't reproduce. Your tsconfig.json causes tsc to bail with

error TS5051: Option 'sourceRoot can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.

Once I remove the sourceRoot option, there are no references to exports in the output.


$ ls

my.ts       tsconfig.json

$ cat my.ts

console.log(1)

$ cat tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "noImplicitAny": true,
    "rootDir": ".",
    "sourceRoot": "../../../",
    "outDir": "../../../js/dist/",
    "sourceMap": false
  },
  "exclude": [
    "node_modules"
  ]
}

$ tsc --version

Version 3.5.3
like image 130
Nickolay Avatar answered Oct 05 '22 22:10

Nickolay