Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in svelte.config.js Syntax Error: Cannot use import statement outside a module

I setting up svelte.config.js like code below:

import preprocess from 'svelte-preprocess';

const config = {
  preprocess: preprocess(),
};

export default config;

Suddenly, my Svelte codes keep getting error Error in svelte.config.js SyntaxError: Cannot use import statement outside a module

How to fix this issue? But I still be able to run the project using npm

like image 743
flyingduck92 Avatar asked Feb 20 '26 19:02

flyingduck92


1 Answers

You're likely not using "type": "module" in your package.json, so import statements don't work in svelte.config.js. You have three ways to fix this:

  • Use require() instead (also see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/in-general.md#generic-setup)
  • Rename svelte.config.js to svelte.config.mjs
  • Set "type": "module" in your package.json (may break other scripts)
like image 92
dummdidumm Avatar answered Feb 22 '26 14:02

dummdidumm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!