sveltesvelte-3

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


Solution

  • 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: