为什么无法使用“import ... as”导入默认导出与BabelJS [英] Why cant I import a default export with "import ... as" with BabelJS
问题描述
在BabelJS版本5.6.4中,我似乎无法导入...。以下是我想要做的例子:
在文件'test.js'中:
export default class Test {};
在文件'test2.js'(在同一目录中):
导入从./test导入Test2作为Test2;
我也尝试过:
import {Test as Test2} from'./test';
即使在这里没有提到:
http://babeljs.io/docs/learn-es2015/#modules
这里只使用非默认语法中的括号:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
<有没有人成功完成了?
编辑:绝对是因为默认值
关键字。所以,在这种情况下,问题就变成了,有没有人有链接到文档,指出我不能够默认导入别名? ECMA或Babel。
您可以通过
导入默认导出pre>
从'./test'导入Test2;
或
import {default as Test2} from'./test';
默认导出没有测试
作为您需要别名的名称 - 您只需要以所需的名称导入默认值。
我发现的最好的文档是文章 ECMAScript 6模块:Axel Rauschmayers中的最终语法 博客。
In version 5.6.4 of BabelJS, I seemingly cannot "import ... as." Here are examples of what I am trying to do:
In file 'test.js':
export default class Test {};
In file 'test2.js' (in the same directory):
import Test as Test2 from './test';
I have also tried to do:
import {Test as Test2} from './test';
Even though it says nothing about that here: http://babeljs.io/docs/learn-es2015/#modules
And only uses brackets in the non-default syntax here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
Has anyone done this successfully?
EDIT: It is absolutely because of the default
keyword. So, in this case, the question becomes, does anyone have any links to documentation that states that I should not be able to alias a default import? ECMA or Babel.
You can import the default export by either
import Test2 from './test';
or
import {default as Test2} from './test';
The default export doesn't have Test
as a name that you would need to alias - you just need to import the default under the name that you want.
The best docs I've found so far is the article ECMAScript 6 modules: the final syntax in Axel Rauschmayers blog.
这篇关于为什么无法使用“import ... as”导入默认导出与BabelJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!