I am in a Svelte
project and I have an issue:
- My files are showing no errors in VSCode, but when executing
npm run dev --
all Typescript syntax are shown as error and the server won't start.
So I tried removing all node_modules and reinstalling them, but now when I run node scripts/setupTypeScript.js
I have the following error:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\(...)\my-app\scripts\setupTypeScript.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
I tried reinstalling TypeScript globally (npm install typescript@latest -g
), but that didn't help. I didn't find anyone with the same issue...
-- Note that it was working perfectly fine, until I did something I don't recall (trying to write something but it was received as shortcut and tampered with my files - I couldn't find anything special in the diff from the git repo, except package.json
some version (TS related) were upgraded.)
Edit
(Before to reproduce my mistakes, please look below at the answer.)
So apparently the ./scripts/
folder should exists and doesn't. So i recreated it :
mkdir tmp
cd tmp
npx degit sveltejs/template svelte-typescript-app
cp -r svelte-typescript-app/scripts ../
cd ../
rm -r tmp
But running it now gives me another error that I didn't have before:
> node scripts/setupTypeScript.js
node:internal/fs/utils:344
throw err;
^
at Object.renameSync (node:fs:980:3)
at Object.<anonymous> (C:\(...)\my-app\scripts\setupTypeScript.js:44:4)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
errno: -4058,
syscall: 'rename',
code: 'ENOENT',
path: 'C:\(...)\my-app\src\\main.js',
dest: 'C:\(...)\my-app\src\\main.ts'
}
Actually it is trying to convert main.js into main.ts, but because I already run it, it doesn't work.
So I renamed it back into main.js
and it was successful, but now running npm run dev --
gives me an error about Error: Identifier 'sveltePreprocess' has already been declared
, indeed, it appears twice in rollup.config.js
, just removing the redundancy solves the issue. Warning: There are other duplicated lines.
Conclusion
In the end I still have the syntax error popping up, and the scripts/
directory disappeared again.
See the answer below