Skip to content

onMount Error: Function called outside component initialization #3658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jackylee941130 opened this issue Oct 4, 2019 · 2 comments
Closed
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@jackylee941130
Copy link

I have read sveltejs/sapper#592 but all of the solutions are not working. Is there any solution to fix this issue?

<script>
    import { onMount } from 'svelte';

    let myVar = [];

    onMount(async () => {
        myVar = await {someAPICall};
    })
</script>
@Conduitry
Copy link
Member

Do you have a minimal reproduction? Calling onMount like that should work.

@Conduitry Conduitry added the awaiting submitter needs a reproduction, or clarification label Oct 4, 2019
@jackylee941130
Copy link
Author

Sorry, I have found the problem in my webpack.config.js. '.mjs' must be included in the extensions field.

resolve: {
    extensions: ['.mjs', '.js', '.svelte', '.json']
},
module: {
       {
         test: /\.mjs$/,
         include: /node_modules/,
         type: 'javascript/auto',
         loader: 'babel-loader
       }
     ]
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

2 participants