admin管理员组文章数量:1320661
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
{
"pileOnSave": true,
"pilerOptions": {
"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.
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
{
"pileOnSave": true,
"pilerOptions": {
"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.
Share Improve this question asked Apr 7, 2017 at 12:51 kockburnkockburn 17.6k10 gold badges90 silver badges141 bronze badges 6- Maybe one of these will help you github./wallabyjs/public/issues/845 or github./wallabyjs/public/issues/160 – Ionut Necula Commented Apr 7, 2017 at 13:00
- 2 @lonut thanks for the links, however they were not what I was looking for. – kockburn Commented Apr 7, 2017 at 13:18
- Can you show us your Gruntfile? Are you using System.js (is there a reference to system.js and/or system.js.config somewhere in your project)? I've encountered the same problem and have managed to fix it. – ACOMIT001 Commented Apr 9, 2017 at 6:43
- @ACOMIT001 if no module is specified then I believe by default monjs is chosen. I'm using the tsc piler and not grunt. I've also tried by specifying the system module, but was unable to get it to work properly. What was your solution? – kockburn Commented Apr 9, 2017 at 7:23
- 1 I was actually having a similar problem with Jasmine. Creating a file with exports defined managed to fix the issue. – ACOMIT001 Commented Apr 9, 2017 at 13:07
2 Answers
Reset to default 1I 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
{
"pileOnSave": true,
"pilerOptions": {
"target": "es5",
"noImplicitAny": true,
"rootDir": ".",
"sourceRoot": "../../../",
"outDir": "../../../js/dist/",
"sourceMap": false
},
"exclude": [
"node_modules"
]
}
$ tsc --version
Version 3.5.3
- Change
module
code generation option toes6
intsconfig.json
"module": "es6",
So, the code generated by the tsc
for import
is supported by the browser.
- Make sure that your
<script>
tag hastype="module"
:
<script src="index.js" type="module"></script>
- Use
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",
本文标签: javascriptReferenceError Can39t find variable exportsStack Overflow
版权声明:本文标题:javascript - ReferenceError: Can't find variable: exports - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742062728a2418660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论