简体   繁体   English

ES6导入,导出=错误:参数无效

[英]ES6 imports, exports = Error: invalid argument

i have this setup 我有这个设置

file1.js: file1.js:

export function foo1() { ... };

file2.js: file2.js:

export function foo2() { ... }

hook.js: hook.js:

 import {foo1} from './file1';
 import {foo2} from './file2';

 export {foo1, foo2};

Now when i want to import from my hook: 现在,当我想从钩子中导入时:

app.js app.js

import { foo1 } from '../data/hook.js';

i get this: 我得到这个:

Error: invalid argument

When calling foo1. 调用foo1时。 (The function has no arguments/parameters). (该函数没有参数/参数)。

Anyone know what's the problem? 有人知道出什么问题吗?

UPDATE: 更新:

I also get the invalid argument when importing foo1 directly from file1. 直接从file1导入foo1时,也会得到invalid argument Is this a Babel Problem? 这是通天塔问题吗?

My .babelrcb( i use test as environment): 我的.babelrcb(我使用test作为环境):

"env": {
  "targets": {
    "node": "4.8.4"
  },
  "test": {
    "presets": ["env"]
  },
}

UPDATE AND SOLUTION: 更新和解决方案:

It turned out the import was correct, thx for all the guys who helped me on this Q. The problem was due to a Promise inside the function foo1 which caused the import to fail: 事实证明,导入是正确的,对所有在此问题上帮助过我的人来说都是正确的。问题是由于函数foo1中的Promise导致导入失败:

browser.waitUntil(..); // see http://webdriver.io/api/utility/waitUntil.html

you have to add ./ in import and default in the export 您必须在导入中添加./ ,并在导出中default

File1.js File1.js

export default function foo1()

hook.js hook.js

import {foo1} from './File1'

otherwise, it will search for File1 in node_modules 否则,它将在node_modules中搜索File1

reference 参考

Function body is missing on file1 and file2. 在file1和file2上缺少函数主体。

file1.js: file1.js:

export function foo1() {};

file2.js: file2.js:

export function foo2() {};

On hook.js, you should export default. 在hook.js上,您应该导出默认值。

import {foo1} from './file1';
import {foo2} from './file2';

export default {foo1, foo2};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM