-
Notifications
You must be signed in to change notification settings - Fork 8
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
Error code 500: Cannot use import statement outside a module #3
Comments
Update Aug. 24, 2021It should not be required to optimize "dayjs" if using a vite-powered set-up (e.g., SvelteKit or
|
Hi @metonym , commenting due to same issue here with SvelteKit. To further clarify: Using svelte-time on its own works! Importing dayjs for further i18n modules then fails.
|
@rvrm Interesting. Would you mind sharing your svelte.config.js? This is my set-up: package.json
{
"private": true,
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"preview": "svelte-kit preview"
},
"devDependencies": {
"@sveltejs/kit": "next",
"svelte": "^3.34.0",
"svelte-time": "^0.3.0"
},
"type": "module"
}
svelte.config.js /** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: "#svelte",
vite: {
optimizeDeps: {
exclude: ["dayjs"],
},
},
},
};
export default config; src/routes/index.svelte <script context="module">
import "dayjs/esm/locale/de";
import dayjs from "dayjs/esm";
dayjs.locale("de");
</script>
<script>
import Time from "svelte-time";
</script>
<Time />
Output In my browser, "Juni 07, 2021" is rendered. |
I also cleared the cache and produced the same result. rm -rf .svelte-kit node_modules/.vite
yarn && yarn dev |
I mistakenly npm installed dayjs on its own. Now realized this step is not necessary. Uninstalling the package and simply import the plugins now worked as intended. Thank you! |
Hey Metonym,
one sweet package you wrote there! I'm tinkering with it but for some reason I always end up having issues with the dayjs module. I'm importing within the module context ala
but always get the following error, when I first navigate to a page using it:
Any idea?
Best,
George
The text was updated successfully, but these errors were encountered: