Closed KeithAndreRose closed 2 years ago
| also tried updating our project to 360
- but also get this during build:
[vite-plugin-svelte-kit] Maximum call stack size exceeded
web-app:build: error during build:
web-app:build: RangeError: Maximum call stack size exceeded
web-app:build: at traverse (file:///Users/alexbjorlig/Documents/eddystone/node_modules/@sveltejs/kit/dist/vite.js:216:19)
web-app:build: at file:///Users/alexbjorlig/Documents/eddystone/node_modules/@sveltejs/kit/dist/vite.js:227:36
web-app:build: at Array.forEach (<anonymous>)
web-app:build: at traverse (file:///Users/alexbjorlig/Documents/eddystone/node_modules/@sveltejs/kit/dist/vite.js:227:18)
web-app:build: at file:///Users/alexbjorlig/Documents/eddystone/node_modules/@sveltejs/kit/dist/vite.js:227:36
web-app:build: at Array.forEach (<anonymous>)
web-app:build: at traverse (file:///Users/alexbjorlig/Documents/eddystone/node_modules/@sveltejs/kit/dist/vite.js:227:18)
web-app:build: at file:///Users/alexbjorlig/Documents/eddystone/node_modules/@sveltejs/kit/dist/vite.js:227:36
web-app:build: at Array.forEach (<anonymous>)
web-app:build: at traverse (file:///Users/alexbjorlig/Documents/eddystone/node_modules/@sveltejs/kit/dist/vite.js:227:18)
I too got the same error after upgrading to 360 .
[vite-plugin-svelte-kit] Maximum call stack size exceeded
--
13:58:58.834 | Done in 97.07s.
13:58:58.859 | Error: No Output Directory named "public" found after the Build completed. You can configure the Output Directory in your Project Settings. Learn More: https://vercel.link/missing-public-directory
reverting to "@sveltejs/kit": "1.0.0-next.359",
and then it builds fine
Getting the same error when importing monaco-editor
on 360
: https://github.com/NASA-AMMOS/aerie-ui/blob/develop/src/components/ui/MonacoEditor.svelte#L71
[vite-plugin-svelte-kit] Maximum call stack size exceeded
Looks like the common issue is monaco-editor
. I too use the same and have the same issue.
Hi @KeithAndreRose - you have mentioned a workaround. Would it be possible for you to share how to use the cdn import to solve this issue in the interim ?
@tsukhu Referencing the implementation in this gist.
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.21.2/min/vs/loader.min.js"></script>
Could be added to the <head>
of src/app.html
Then the editor setup using
<script>
import { onMount } from 'svelte';
let container
onMount(async () => {
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.21.2/min/vs' } })
window.MonacoEnvironment = {
getWorkerUrl: function (workerId, label) {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
self.MonacoEnvironment = {
baseUrl: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.21.2/min/'
};
importScripts('https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.21.2/min/vs/base/worker/workerMain.js');`)}`
}
}
require(['vs/editor/editor.main'], function () {
monaco.editor.create(container, {
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
language: 'javascript'
})
})
})
</script>
<div bind:this={container} style="width:800px;height:600px;border:1px solid grey"></div>
Thank you @KeithAndreRose - This worked perfectly. My vercel build time has also reduced by 20 seconds :-) after this (the transform for all the monaco libraries during the build is now gone).
I looked into this one a bit today. Essentially this is happening because of a circular dependency in Monaco, and the traverse
function not adding the dynamic import from the circular dependency to the imports
Set. For example here is my test component:
<script>
import { onMount } from 'svelte';
onMount(async () => {
await import('monaco-editor/esm/vs/language/typescript/monaco.contribution.js');
});
</script>
And here is my corresponding .svelte-kit/output/client/_app/manifest.json
file (truncated a bit to make it more clear):
{
"src/routes/index.svelte": {
"file": "immutable/pages/index.svelte-93e06e99.js",
"src": "src/routes/index.svelte",
"isEntry": true,
"isDynamicEntry": true,
"imports": [
"_preload-helper-96c8edfa.js",
"_index-06f608d5.js"
],
"dynamicImports": [
"_monaco.contribution-0af8d1ea.js"
]
},
"_index-06f608d5.js": {
"file": "immutable/chunks/index-06f608d5.js"
},
"_preload-helper-96c8edfa.js": {
"file": "immutable/chunks/preload-helper-96c8edfa.js"
},
"_monaco.contribution-0af8d1ea.js": {
"file": "immutable/chunks/monaco.contribution-0af8d1ea.js",
"isDynamicEntry": true,
"imports": [
"_preload-helper-96c8edfa.js"
],
"dynamicImports": [
"node_modules/.pnpm/monaco-editor@0.33.0/node_modules/monaco-editor/esm/vs/language/typescript/tsMode.js"
],
"css": [
"immutable/assets/monaco.contribution-9deb5b7b.css"
],
"assets": [
"immutable/assets/codicon-c99115f8.ttf"
]
},
"node_modules/.pnpm/monaco-editor@0.33.0/node_modules/monaco-editor/esm/vs/language/typescript/tsMode.js": {
"file": "immutable/chunks/tsMode-d0fba56e.js",
"src": "node_modules/.pnpm/monaco-editor@0.33.0/node_modules/monaco-editor/esm/vs/language/typescript/tsMode.js",
"isDynamicEntry": true,
"imports": [
"_monaco.contribution-0af8d1ea.js",
"_preload-helper-96c8edfa.js"
]
}
}
Here is the traverse
call stack (paths simplified to make it more clear) :
traverse('src/routes/index.svelte', true);
traverse('_monaco.contribution.js', false); // Dynamic, not added to imports Set
traverse('tsMode.js', false); // Dynamic, not added to imports Set
traverse('_monaco.contribution.js', false); // Non-dynamic but not added to imports Set because add_js is false
traverse('tsMode.js', false); // Dynamic, not added to imports Set
traverse('_monaco.contribution.js', false); // Non-dynamic but not added to imports Set because add_js is false
traverse('tsMode.js', false); // Dynamic, not added to imports Set
...
Since tsMode.js
is always dynamically imported from _monaco.contribution.js
it never gets added to the imports
Set and thus recurses until the overflow. A quick fix would be modifying traverse
:
// add_js is true at first so the dynamic import is added to the imports Set for all recursive calls
chunk.dynamicImports.forEach((file) => traverse(file, add_js));
But I don't know if we want to add dynamic imports to the imports
Set like this. @Rich-Harris Any ideas on this? Happy to work on a PR for this with some direction. Thanks!
Describe the bug
Starting in next.360 my CI/CD build script failed with
[vite-plugin-svelte-kit] Maximum call stack size exceeded
I poked around and found it coming from recurse calls to thetraverse
procedure added apart of #5138I modified the
traverse
function to debugand these where the last few lines.
I had been dynamically importing
monaco-editor
in one my layouts. There are workaround importing via cdnjs however being able to dynamically import it is a lot more desired.Script to reproduce with starter project added below.
Reproduction
Logs
System Info
Severity
serious, but I can work around it
Additional Information
No response