admin管理员组文章数量:1401933
I have a reproduction for this issue here.
Essentially I have a TSConfig with
"module": "None",
I have two files:
//index.ts
import {foo} from "./other";
function main(){
foo();
}
main();
and
//other.ts
export function foo() {
console.log("x")
}
I'm expecting this to error, because as I understand it, modules are not allowed.
However, if I compile this with tsc
then it compiles without error, and it creates CJS module code.
However, if I compile it with tsc --module none --outfile dist/o.js src/index.ts
Then I get the error I expect:
src/other.ts:1:17 - error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
1 export function foo() {
~~~
Found 1 error in src/other.ts:1
What gives?
I have a reproduction for this issue here.
Essentially I have a TSConfig with
"module": "None",
I have two files:
//index.ts
import {foo} from "./other";
function main(){
foo();
}
main();
and
//other.ts
export function foo() {
console.log("x")
}
I'm expecting this to error, because as I understand it, modules are not allowed.
However, if I compile this with tsc
then it compiles without error, and it creates CJS module code.
However, if I compile it with tsc --module none --outfile dist/o.js src/index.ts
Then I get the error I expect:
src/other.ts:1:17 - error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
1 export function foo() {
~~~
Found 1 error in src/other.ts:1
What gives?
Share Improve this question edited Mar 25 at 1:49 dwjohnston asked Mar 24 at 6:11 dwjohnstondwjohnston 12k39 gold badges117 silver badges218 bronze badges 4 |1 Answer
Reset to default 2Looking at the only place where that error message is used in the TypeScript codebase, we can see that the condition includes languageVersion < ScriptTarget.ES2015
. This is presumably because ECMAScript modules became part of the standard in ES6/ES2015.
When you compile via tsc --module none --outfile dist/o.js src/index.ts
, whatever target
value you may have in your tsconfig.json
is ignored and the default (ES5) is used, which is why this error is visible.
本文标签: TypeScript module quotNonequot does not errorStack Overflow
版权声明:本文标题:TypeScript: module: "None" does not error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744258247a2597584.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
--module None
also works, shows the error. – dwjohnston Commented Mar 24 at 6:17