typescript 提供“--isolatedModules”标志时无法编译命名空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33977054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot compile namespaces when the '--isolatedModules' flag is provided
提问by Hongbo Miao
I am using urigo:angular2-meteor. When I add an empty main.ts in server folder, it always shows:
我正在使用urigo:angular2-meteor。当我在服务器文件夹中添加一个空的 main.ts 时,它总是显示:
Cannot compile namespaces when the '--isolatedModules' flag is provided.
提供“--isolatedModules”标志时无法编译命名空间。
Even I added the code below on the top of main.ts, it still shows same thing.
即使我在 main.ts 顶部添加了下面的代码,它仍然显示相同的内容。
/// <reference path="../typings/angular2-meteor.d.ts" />
采纳答案by Guenter Guckelsberger
I had the same problem and I added tsconfig.json
into the root directory of my project.
我有同样的问题,我添加tsconfig.json
到我的项目的根目录中。
{
"compilerOptions": {
"isolatedModules": false
}
}
I didn't have the time to dive into it, but it solved the problem.
我没有时间深入研究它,但它解决了问题。
回答by Priyanshu Chauhan
I faced similar issue in react + ts. I had commented out all my code.
我在 react + ts 中遇到了类似的问题。我已经注释掉了我所有的代码。
Turns out A global file cannot be compiled using '--isolatedModules'. Ensure your file contains imports, exports, or an 'export {}' statement.
结果发现 不能使用“--isolatedModules”编译全局文件。确保您的文件包含导入、导出或“export {}”语句。
So, added something like:
因此,添加了以下内容:
export const foo = 'foo';
It's a temporary solution, else you can delete the file with commented code or update tsconfig.json
这是一个临时解决方案,否则您可以删除带有注释代码的文件或更新tsconfig.json
回答by QauseenMZ
I was getting this error when file was not imported in any other file. Importing it in any other file (import {} from "/the-filename-having-compilation-error"), removed this error.
当文件未导入任何其他文件时,我收到此错误。在任何其他文件中导入它(从“/the-filename-have-compilation-error”导入 {}),消除了这个错误。
回答by Abbas Habibnejad
I had the same problem. I was made a component and never use that. When I imported that component In one of my page and use that and RERUN the project again , error was disappear.
我有同样的问题。我被做成了一个组件,从不使用它。当我在我的一个页面中导入该组件并使用该组件并再次重新运行项目时,错误消失了。
回答by Suman N
If you have eslint installed check the rules section in .eslintrc.json file for any contradicting action.If the action you perforned is against the rule defined then error appears.
如果您安装了 eslint,请检查 .eslintrc.json 文件中的规则部分是否有任何矛盾的操作。如果您执行的操作违反了定义的规则,则会出现错误。