Issue
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
Solution
So, for those in the same situation, here is the detailled explanation:
- The
setupTypeScript.js
is not working because the directoryscripts/
is missing. - If you already ran it, the script automatically deleted itself, and its folder. (reason why it's missing...)
- Fact is, that you should not re-run the script
setupTypeScript.js
a second time, if you already ran it. - If you are not sure if you already ran it, check the file
main.js/ts
if it is named :main.ts
the scriptsetupTypeScript.js
has probably already been run. - If you think you didn't execute the script
setupTypeScript.js
and you need to do it but don't have it, then you can download it like this
npx degit sveltejs/template/scripts scripts
If your main is already named main.ts
, it will throw an error (at Object.renameSync (node:fs:980:3)
) then, rename it to main.js
.
If you already ran the script, it will duplicate some lines in rollup.config.js
, make sure : import sveltePreprocess from 'svelte-preprocess';
and import typescript from '@rollup/plugin-typescript';
are not duplicated.
Hope it helps.
Answered By - vinalti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.