0

i have this setup

file1.js:

export function foo1() { ... }; 

file2.js:

export function foo2() { ... } 

hook.js:

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

Now when i want to import from my hook:

app.js

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

i get this:

Error: invalid argument 

When calling foo1. (The function has no arguments/parameters).

Anyone know what's the problem?

UPDATE:

I also get the invalid argumentwhen importing foo1 directly from file1. Is this a Babel Problem?

My .babelrcb( i use test as environment):

"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:

browser.waitUntil(..); // see http://webdriver.io/api/utility/waitUntil.html 
3
  • function foo1(); is a syntax error. Did you mean function foo1() {}? Commented Nov 10, 2017 at 10:15
  • yeah sure i have a full function, see update, that's what it looks like Commented Nov 10, 2017 at 10:20
  • Can you try reproducing it using a plunker or fiddle? Commented Nov 10, 2017 at 10:51

2 Answers 2

1

you have to add ./ in import and default in the export

File1.js

export default function foo1()

hook.js

import {foo1} from './File1'

otherwise, it will search for File1 in node_modules

reference

Sign up to request clarification or add additional context in comments.

4 Comments

ah yes i have it like this in my hook. as well as in the module that imports from the hook
with defaulti am getting TypeError: (0 , _file1.foo) is not a function
there must some other error, will you please post the complete code of your function.
You are absolutely right my friend, the function uses a promise: browser.waituntil(..) this must be the reason why the import fails.
1

Function body is missing on file1 and file2.

file1.js:

export function foo1() {}; 

file2.js:

export function foo2() {}; 

On hook.js, you should export default.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.