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

Viewed 2320

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

2 Answers

I fixed the issue by setting up Svelte Language-server: Runtime on VSCode

Go to File > Preferences > Settings search svelte in searchbox, then find Svelte > Language-server: Runtime

After that, add full path node.exe (e.g: C:\\Program Files\\nodejs\\node.exe) to Svelte > Language-server: Runtime

Related