-
-
Notifications
You must be signed in to change notification settings - Fork 432
Function called outside component initialization #592
Comments
The generated code calls |
This is a svelte issue. sveltejs/svelte#2156 |
It looks like the issue stems from having "svelte" as a dependency instead of a devDependencies in This causes See Excluded packages in rollup.config.js: svelte as a devDependency so the npm package is not used by the server runtime: https://github.com/sveltejs/sapper-template/blob/rollup-v3/package.json#L22 |
The above wasn't relevant for me - from the docs:
You can't call a function outside of component initialization... Moving it to the standard |
I know that since we bundle it, makes no difference if svelte is dep or devDep, but makes sense to me set things that my code import as dep and even eslint complains about it. DX:
Maybe we should offer better solution for this. |
What eslint rule or plugin says that Having the bundler config bundle dev deps and leave prod deps as external seems to be the sanest thing it could default to, and I don't see us wanting to change that. |
Thank you for replying fast. ☮️ ESlint rule about dependencies. We could at least try to offer better error message for this, before it becomes our next NullPointerException, Segmentation Fault or Kernel Panic (more memes). When the message say In the last case we could suggest dependency-cruiser or similar in templates. edit: I wasn't aware that yarn had dependency validation. |
According to the readme for that plugin, it should allow imports of devDependencies unless you specifically configure that to be disallowed, so I'm not sure what you're seeing there. And the Sapper template can't really guard against it if you decide to move something from devDependencies to dependencies. I don't think we need more tooling here. |
Got this issue migrating my project to Svelte 3. |
Instead of the common form
this works similarly like this:
|
I'm getting a
Function called outside component initialization
error from a sapper v0.26.0-alpha.10 project.A component is being loaded from a index.html route component. This component is calling onMount, beforeUpdate, afterUpdate, or onDestroy.
I tried moving onMount into a setTimeout & the same issue occurs.
Unfortunately, I'm not able to reproduce it in the repl. Hopefully, this will be fixed or a reproduction for this issue will emerge.
The text was updated successfully, but these errors were encountered: