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
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:
require()
instead (also see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/in-general.md#generic-setup)svelte.config.js
to svelte.config.mjs
"type": "module"
in your package.json
(may break other scripts)