question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: action.default is not a function

See original GitHub issue

I have created a new route that works perfectly fine when I navigate to it from a different route via the Link Component but when I enter the url in the browser and open the page directly all I get is this TypeError:

TypeError: action.default is not a function
    at context.route.load.then.action ([....]/src/router.js:16:1)

I don’t really get what it’s trying to tell me.

My routes.js (the swiper route fails)

const routes = {
  path: '/',

  // Keep in mind, routes are evaluated in order
  children: [
    {
      path: '/',
      load: () => import(/* webpackChunkName: 'home' */ './home'),
    },
    {
      path: '/swiper',
      load: () => import(/* webpackChunkName: 'swiper' */ './swiper'),
    },

    // Wildcard routes, e.g. { path: '*', ... } (must go last)
    {
      path: '*',
      load: () => import(/* webpackChunkName: 'not-found' */ './not-found'),
    },
  ],

  async action({ next }) {
    // Execute each child route until one of them return the result
    const route = await next();

    // Provide default values for title, description etc.
    route.title = `${route.title || 'Untitled Page'} - x`;
    route.description = route.description || '';

    return route;
  },
};

And the swiper/index.js route:


function action() {
  return {
    chunks: ['swiper'],
    title: 'Swiper',
    component: (
      <Layout>
        <Swiper />
      </Layout>
    ),
  };
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
frenzzycommented, Sep 2, 2017

swiper/index.js must export action fn:

export default action;
0reactions
tusharkotlapurecommented, Dec 21, 2018

@damiangreen I am using react-quill lib, and when I use that component it is showing me the same error, for my other component page is rendering but only for this component it’s showing this error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: action.default is not a function - Stack Overflow
First, check what is present in then((action). add check if (action && action.default === 'function'). if it is true then call the function...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
is not a function or its return value is not iterable in ReactJs ...
React Nodejs Expressjs & MongoDB bug fixing. TypeError : default is not a function or its return value is not iterable in ReactJs...
Read more >
'X' is not a function TypeError in React [Solved] | bobbyhadz
Another common reason the "Uncaught TypeError: X is not a function" error occurs in React is when we try to call a function...
Read more >
How to Handle JavaScript Uncaught TypeError: “x” is Not a ...
The Javascript error TypeError: "x" is not a function occurs when there is an attempt to call a function on a value or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found