profile
viewpoint

Ask questionsonMount Error: Function called outside component initialization

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>
sveltejs/svelte

Answer questions jackylee941130

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
       }
     ]
   }
useful!

Related questions

Javascript Interpolation in Styles via CSS Variables? hot 2
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Uncaught TypeError: y.fragment.l is not a function hot 1
Increase elements when using a combination of await block and transition hot 1
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Change body class via &lt;svelte:body /&gt; hot 1
Site: Svelte Cookbook/ Examples hot 1
Missing dependencies in svelte/compiler type definitions hot 1
Multiple components in one file - svelte hot 1
A way to see if slot prop is present hot 1
slot inside #if inside #each : TypeError cannot read property 'd' of null hot 1
unclear / difficult to import uuidv4 hot 1
Use <script type="application/ld+json"> in <svelte:head> hot 1
Error: 'default' is not exported when using babel + moment hot 1
Outros undefined when transitioning to another page hot 1
Github User Rank List