Reputation: 17616
Why am I getting the following error? Did I forget to include a script in my html?
ReferenceError: Can't find variable: exports
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* more code */
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.
Upvotes: 15
Views: 8088
Reputation: 6667
module
code generation option to es6
in tsconfig.json
"module": "es6",
So, the code generated by the tsc
for import
is supported by the browser.
<script>
tag has type="module"
:<script src="index.js" type="module"></script>
importmap
in your .html
to resolve the module paths:<script type="importmap">
{
"mymodule": "/path/to/mymodule.js",
}
</script>
or even load it from CDN:
"mymodule": "https://thecdnlink",
Upvotes: 0
Reputation: 32063
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
Upvotes: 1